or
@using NursingHomeStock.Resources@model NursingHomeStock.Models.NursingHomeViewModel@{ ViewBag.Title = "Edit"; Layout = "../Shared/_Layout.cshtml";}@using (Html.BeginForm("Edit", "NursingHome", FormMethod.Post, new { @class = "form-horizontal", @role = "form" })){ @Html.AntiForgeryToken() <fieldset> <legend>Bearbeiten</legend> <div class="well"> <div class="form-group"> @Html.LabelFor(model => model.Name, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @Html.TextBoxFor(model => model.Name, new { @class = "form-control" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Street, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @Html.TextBoxFor(model => model.Street, new { @class = "form-control" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PostalCode, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @Html.TextBoxFor(model => model.PostalCode, new { @class = "form-control" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.City, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @Html.TextBoxFor(model => model.City, new { @class = "form-control" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Description, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @Html.TextBoxFor(model => model.Description, new { @class = "form-control" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Phone, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @Html.TextBoxFor(model => model.Phone, new { @class = "form-control" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Fax, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @Html.TextBoxFor(model => model.Fax, new { @class = "form-control" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.EMail, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @Html.TextBoxFor(model => model.EMail, new { @class = "form-control" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Website, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @Html.TextBoxFor(model => model.Website, new { @class = "form-control" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.RTName, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @Html.TextBoxFor(model => model.RTName, new { @class = "form-control" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.RTAddress, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @Html.TextBoxFor(model => model.RTAddress, new { @class = "form-control" }) </div> </div> </div> <div class="well"> <table class="table-condensed table-responsive"> <thead> <tr> <th></th> <th>@GlobalResources.Capacity</th> <th>@GlobalResources.Approved</th> </tr> </thead> <tbody> <tr> <td>@GlobalResources.LongTimeCare</td> <td> @(Html.Kendo().NumericTextBoxFor(model => model.CapacityLongTimeCare) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </td> <td> @(Html.Kendo().NumericTextBoxFor(model => model.ApprovedLongTimeCare) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </td> </tr> <tr> <td>@GlobalResources.ShortTimeCare</td> <td> @(Html.Kendo().NumericTextBoxFor(model => model.CapacityShortCare) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </td> <td> @(Html.Kendo().NumericTextBoxFor(model => model.ApprovedShortTimeCare) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </td> </tr> <tr> <td>@GlobalResources.DailySupport</td> <td> @(Html.Kendo().NumericTextBoxFor(model => model.CapacityDailyCare) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </td> <td> @(Html.Kendo().NumericTextBoxFor(model => model.ApprovedDailySupport) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </td> </tr> <tr> <td>@GlobalResources.LongTimeSupport</td> <td> @(Html.Kendo().NumericTextBoxFor(model => model.CapacityLongTimeSupport) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </td> <td> @(Html.Kendo().NumericTextBoxFor(model => model.ApprovedLongTimeSupport) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </td> </tr> <tr> <td>@GlobalResources.AlternativeLivingEnvironmentLong</td> <td> @(Html.Kendo().NumericTextBoxFor(model => model.CapacityAlternativeLivingEnvironment) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </td> <td> @(Html.Kendo().NumericTextBoxFor(model => model.ApprovedAlternativeLivingEnvironment) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </td> </tr> </tbody> </table> </div> <div class="well"> <table class="table-condensed table-responsive"> <tbody> <tr> <td>@GlobalResources.LongTimeCare</td> <td> <div class="input-group"> <span class="input-group-addon"><span class="fa fa-user"></span></span> @(Html.Kendo().NumericTextBoxFor(model => model.LongTimeCareI) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </div> </td> <td> <div class="input-group"> <span class="input-group-addon"><span class="fa fa-female"></span></span> @(Html.Kendo().NumericTextBoxFor(model => model.LongTimeCareII_f) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </div> </td> <td> <div class="input-group"> <span class="input-group-addon"><span class="fa fa-male"></span></span> @(Html.Kendo().NumericTextBoxFor(model => model.LongTimeCareII_m) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </div> </td> </tr> <tr> <td>@GlobalResources.ShortTimeCare</td> <td> <div class="input-group"> <span class="input-group-addon"><span class="fa fa-user"></span></span> @(Html.Kendo().NumericTextBoxFor(model => model.ShortTimeCare) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </div> </td> <td> @(Html.Kendo().DatePickerFor(model => model.ShortTimeCareForDate) .Name("ShortTimeCareForDate") //.Format("dd.MM.yyyy") .Format("yyyy-MM-dd") ) </td> <td></td> </tr> <tr> <td>@GlobalResources.DailySupport</td> <td> <div class="input-group"> <span class="input-group-addon"><span class="fa fa-user"></span></span> @(Html.Kendo().NumericTextBoxFor(model => model.DailySupport) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </div> </td> <td></td> <td></td> </tr> <tr> <td>@GlobalResources.LongTimeSupport</td> <td> <div class="input-group"> <span class="input-group-addon"><span class="fa fa-user"></span></span> @(Html.Kendo().NumericTextBoxFor(model => model.LongTimeSupportI) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </div> </td> <td> <div class="input-group"> <span class="input-group-addon"><span class="fa fa-female"></span></span> @(Html.Kendo().NumericTextBoxFor(model => model.LongTimeSupportII_f) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </div> </td> <td> <div class="input-group"> <span class="input-group-addon"><span class="fa fa-male"></span></span> @(Html.Kendo().NumericTextBoxFor(model => model.LongTimeSupportII_m) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </div> </td> </tr> <tr> <td>@GlobalResources.AlternativeLivingEnvironmentLong</td> <td> <div class="input-group"> <span class="input-group-addon"><span class="fa fa-user"></span></span> @(Html.Kendo().NumericTextBoxFor(model => model.AlternativeLivingEnvironmentI) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </div> </td> <td> <div class="input-group"> <span class="input-group-addon"><span class="fa fa-female"></span></span> @(Html.Kendo().NumericTextBoxFor(model => model.AlternativeLivingEnvironmentII_f) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </div> </td> <td> <div class="input-group"> <span class="input-group-addon"><span class="fa fa-male"></span></span> @(Html.Kendo().NumericTextBoxFor(model => model.AlternativeLivingEnvironmentII_m) .IncreaseButtonTitle(GlobalResources.Increase) .DecreaseButtonTitle(GlobalResources.Decrease) .Format("n0") .Min(0) ) </div> </td> </tr> </tbody> </table> </div> <div class="well"> <div class="form-group"> @Html.LabelFor(model => model.IsAlternative, new { @class = "control-label col-md-3" }) <div class="col-md-9"> <div class="checkbox"> <label> @Html.CheckBoxFor(model => model.IsAlternative) </label> </div> </div> </div> <div class="form-group"> @Html.LabelFor(model => model.CategoryItems, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-9 col-lg-9"> @(Html.Kendo().MultiSelectFor(model => model.SelectedCategoryItems) .Name("SelectedCategoryItems") .Placeholder(GlobalResources.AdditionalOffers) .BindTo(Model.CategoryItems) ) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.UserItems, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @(Html.Kendo().DropDownListFor(model => model.UserItems) .Name("ApplicationUserId") .DataTextField("Text") .DataValueField("Value") .BindTo(Model.UserItems) .Value(Model.ApplicationUserId) ) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.RegionItems, new { @class = "col-xs-12 col-sm-12 col-md-3 col-lg-3 control-label" }) <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"> @(Html.Kendo().DropDownListFor(model => model.RegionItems) .Name("RegionId") .DataTextField("Text") .DataValueField("Value") .BindTo(Model.RegionItems) .Value(Model.RegionId.ToString()) ) </div> </div> </div> <div class="well"> <div class="form-group"> <div class="col-md-offset-3 col-lg-offset-3 col-xs-12 col-sm-12 col-md-2 col-lg-2"> <button type="submit" class="btn btn-default">Save</button> </div> </div> </div> </fieldset>}@section Scripts { @Scripts.Render("~/bundles/jqueryval")}@using System.Data.Entity.Core.Common.EntitySql@using NursingHomeStock.Resources@using NursingHomeStock.Utils<!DOCTYPE html><html><head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>@ViewBag.Title</title> @Styles.Render("~/Content/kendo/css") @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/kendo") @{ string culture = System.Globalization.CultureInfo.CurrentCulture.ToString(); } <script type="text/javascript"> //set current to the "en-GB" culture script kendo.culture("@culture"); $(document).ready(function() { App.ServerRootPath = '@HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)@Url.Content("~/")'; }); </script> @Html.Stimulsoft().RenderMvcViewerScripts()</head><body> <div class="navbar navbar-default navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <button type="button" class="navbar-toggle visible-xs pull-left" data-toggle="offcanvas"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> @*@Html.ActionLink(GlobalResources.NursingHomeStock, "Index", "NursingHome", null, new { @class = "navbar-brand" })*@ </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> @Html.MenuLink(GlobalResources.Home, "Index", "NursingHome") @Html.MenuLink(GlobalResources.About, "About", "Home") @if (Request.IsAuthenticated && User.IsInRole("Admin")) { <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">@GlobalResources.Administration <b class="caret"></b></a> <ul class="dropdown-menu"> @Html.MenuLink(GlobalResources.Roles, "Index", "RolesAdmin") @Html.MenuLink(GlobalResources.User, "Index", "UsersAdmin") <li class="divider"></li> @Html.MenuLink(GlobalResources.NewNursingHome, "Create", "NursingHome") @*@Html.MenuLink(GlobalResources.Employees, "Index", "Employee")*@ @*@Html.MenuLink(GlobalResources.Residents, "Index", "Resident")*@ </ul> </li> } @if (Request.IsAuthenticated && (User.IsInRole("Auditor") || User.IsInRole("Admin"))) { <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">@GlobalResources.Reports <b class="caret"></b></a> <ul class="dropdown-menu"> @*<li class="dropdown-header">Demo</li>*@ @*@Html.MenuLink("Demo", "Demo", "Report")*@ @Html.MenuLink(GlobalResources.NursingHome, "Entire", "Report") </ul> </li> } </ul> @Html.Partial("_LoginPartial") </div> </div> </div> <div class="container"> @Html.Partial("_Branding") </div> <div class="container"> <div class="row row-offcanvas row-offcanvas-left"> <div class="col-sm-2 col-md-2 col-lg-2 sidebar sidebar-offcanvas" id="sidebar" role="navigation"> @Html.Partial("_Sidebar") </div> <div class="col-sm-10 col-md-10 col-lg-10 main"> @RenderBody() </div> </div> </div> @Html.Partial("_Footer") @Scripts.Render("~/bundles/bootstrap") @Scripts.Render("~/bundles/angular") <script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script> @Scripts.Render("~/bundles/google") @Scripts.Render("~/bundles/GoogleAnalytics") @Scripts.Render("~/bundles/nursinghomestock") @RenderSection("scripts", required: false)</body></html>using System;using System.Collections.Generic;using System.ComponentModel.DataAnnotations;using System.Web.Mvc;using NursingHomeStock.Entities;using NursingHomeStock.Resources;namespace NursingHomeStock.Models{ public sealed class NursingHomeViewModel { public int Id { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "Name")] public string Name { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "Street")] public string Street { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "PostalCode")] public int PostalCode { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "City")] public string City { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "ModifiedDate")] public DateTime ModifiedDate { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "Phone")] public string Phone { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "Fax")] public string Fax { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "Email")] public string EMail { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "Website")] public string Website { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "RTName")] public string RTName { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "RTAddress")] public string RTAddress { get; set; } public string ApplicationUserId { get; set; } public int RegionId { get; set; } public double? Latitude { get; set; } public double? Longitude { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "Description")] public string Description { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "AlternativeLivingEnvironmentLong")] public bool IsAlternative { get; set; } public bool IsAvailable { get; set; } public int FreePlaces { get; set; } public ApplicationUser ApplicationUser { get; set; } public ICollection<AvailablePlaces> AvailablePlaces { get; set; } // public ICollection<EmployeeTransmission> EmployeeStatsTransmission { get; set; } // public ICollection<ResidentTransmission> ResidentStatsTransmission { get; set; } public ICollection<NursingHomeCapacity> NursingHomeCapacities { get; set; } public ICollection<CategorySet> CategorySet { get; set; } public string RawWebsite { get { if (string.IsNullOrEmpty(Website)) return string.Empty; return Website.StartsWith("http://") ? Website.Substring(7) : Website; } } [Display(ResourceType = typeof(GlobalResources), Name = "ApprovedShortTimeCare")] public int ApprovedShortTimeCare { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "ApprovedDailySupport")] public int ApprovedDailySupport { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "ApprovedLongTimeCare")] public int ApprovedLongTimeCare { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "ApprovedAlternativeLivingEnvironment")] public int ApprovedAlternativeLivingEnvironment { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "ApprovedLongTimeSupport")] public int ApprovedLongTimeSupport { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "CapacityShortCare")] public int CapacityShortCare { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "CapacityDailyCare")] public int CapacityDailyCare { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "CapacityCare")] public int CapacityLongTimeCare { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "CapacityAlternative")] public int CapacityAlternativeLivingEnvironment { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "CapacityAssistance")] public int CapacityLongTimeSupport { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "ShortTimeCare")] public int ShortTimeCare { get; set; } // [DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}", ApplyFormatInEditMode = true)] public DateTime ShortTimeCareForDate { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "DailySupport")] public int DailySupport { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "LongTimeCare")] public int LongTimeCareI { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "LongTimeCare")] public int LongTimeCareII_m { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "LongTimeCare")] public int LongTimeCareII_f { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "LongTimeSupport")] public int LongTimeSupportI { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "LongTimeSupport")] public int LongTimeSupportII_m { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "LongTimeSupport")] public int LongTimeSupportII_f { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "AlternativeLivingEnvironment")] public int AlternativeLivingEnvironmentI { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "AlternativeLivingEnvironment")] public int AlternativeLivingEnvironmentII_m { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "AlternativeLivingEnvironment")] public int AlternativeLivingEnvironmentII_f { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "User")] public SelectList UserItems { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "Region")] public SelectList RegionItems { get; set; } [Display(ResourceType = typeof(GlobalResources), Name = "AdditionalOffers")] public MultiSelectList CategoryItems { get; set; } public List<string> SelectedCategoryItems { get; set; } }}using System;using System.Collections.Generic;using System.Data.Entity;using System.Linq;using System.Net;using System.Net.Mail;using System.Text;using System.Web.Configuration;using System.Web.Mvc;using Microsoft.AspNet.Identity;using NursingHomeStock.Dto;using NursingHomeStock.Entities;using NursingHomeStock.Models;using NursingHomeStock.Resources;using NursingHomeStock.Utils;using NursingHomeStock.Utils.Configuration;using NursingHomeStock.Utils.Configuration.Notification;using PagedList;namespace NursingHomeStock.Controllers{ [Authorize] public class NursingHomeController : Controller { private ApplicationDbContext db = new ApplicationDbContext(); #region Search [AllowAnonymous] public ViewResult Search() { ViewBag.Categories = new MultiSelectList(db.CategorySets.ToList(), "Id", "Name"); ViewBag.Regions = new MultiSelectList(db.Regions.ToList(), "Id", "Name"); return View(); } [HttpPost] [AllowAnonymous] public ViewResult Search(NursingHomeSearchModel nursingHomeSearchModel) { ViewBag.Title = "Suchergebnisse"; ViewBag.Type = "All"; var relevantHomes = GetNursingHomes(nursingHomeSearchModel); return View("Index", relevantHomes); } private List<NursingHomeViewModel> GetNursingHomes(NursingHomeSearchModel nursingHomeSearchModel) { var nursingHomes = db.NursingHomes.ToList(); var nursingHomeViewModels = new List<NursingHomeViewModel>(); foreach (var nursingHome in nursingHomes) { var nursingHomeViewModel = new NursingHomeViewModel(); NursingHomeDto nhDto = new NursingHomeDto(nursingHome, nursingHomeViewModel, db); nhDto.DbObject2ViewModel(); nursingHomeViewModels.Add(nursingHomeViewModel); } return nursingHomeViewModels.Where(nh => NursingHomeFitsToFilter(nursingHomeSearchModel, nh)).ToList(); } private bool NursingHomeFitsToFilter(NursingHomeSearchModel nursingHomeSearchModel, NursingHomeViewModel nh) { var retVal = NursingHomeFitsToParameter(nh, nursingHomeSearchModel.Sex, nursingHomeSearchModel.RoomCategory, nursingHomeSearchModel.CareType); if (nursingHomeSearchModel.RegionList != null && nursingHomeSearchModel.RegionList.Count > 0) { bool isInRegion = false; foreach (var reg in nursingHomeSearchModel.RegionList) { if (isInRegion) continue; isInRegion = nh.RegionId == int.Parse(reg); } retVal = retVal && isInRegion; } if (!string.IsNullOrEmpty(nursingHomeSearchModel.Name)) { if (nursingHomeSearchModel.RoomCategory == null && nursingHomeSearchModel.RegionList == null && nursingHomeSearchModel.CareType == null) retVal = true; retVal = retVal && nh.Name.ToLower().Contains(nursingHomeSearchModel.Name.ToLower()); } return retVal; } private bool NursingHomeFitsToParameter(NursingHomeViewModel nh, string sex, List<string> roomTypes, List<string> careTypes) { bool roomTypesFit = false; bool isMale = sex == "male"; if (roomTypes != null && roomTypes.Count > 0) { foreach (var rt in roomTypes) { if (roomTypesFit) break; switch (rt) { case "OneBed": if (careTypes != null && careTypes.Count > 0) { foreach (var ct in careTypes) { switch (ct) { case "Ltc": roomTypesFit = nh.LongTimeCareI > 0; break; case "Stc": roomTypesFit = nh.ShortTimeCare > 0; break; case "Ds": roomTypesFit = nh.DailySupport > 0; break; case "Lts": roomTypesFit = nh.LongTimeSupportI > 0; break; case "Ale": roomTypesFit = nh.AlternativeLivingEnvironmentI > 0; break; } } } //no care type chosen else if (nh.LongTimeCareI + nh.AlternativeLivingEnvironmentI + nh.LongTimeSupportI > 0 + nh.DailySupport + nh.ShortTimeCare) roomTypesFit = true; break; case "TwoBed": if (careTypes != null && careTypes.Count > 0) { foreach (var ct in careTypes) { switch (ct) { case "Ltc": roomTypesFit = isMale ? nh.LongTimeCareII_m > 0 : nh.LongTimeCareII_f > 0; break; case "Stc": roomTypesFit = nh.ShortTimeCare > 0; break; case "Ds": roomTypesFit = nh.DailySupport > 0; break; case "Lts": roomTypesFit = isMale ? nh.LongTimeSupportII_m > 0 : nh.LongTimeSupportII_f > 0; break; case "Ale": roomTypesFit = isMale ? nh.AlternativeLivingEnvironmentII_m > 0 : nh.AlternativeLivingEnvironmentII_f > 0; break; } } } else { //no care type chosen roomTypesFit = isMale ? nh.LongTimeCareII_m + nh.ShortTimeCare + nh.DailySupport + nh.LongTimeSupportII_m + nh.AlternativeLivingEnvironmentII_m > 0 : nh.LongTimeCareII_f + nh.ShortTimeCare + nh.DailySupport + nh.LongTimeSupportII_f + nh.AlternativeLivingEnvironmentII_f > 0; } break; } } } return roomTypesFit; } #endregion Search // GET: /NursingHome/Details/5 [AllowAnonymous] public ActionResult Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } NursingHome nursinghome = db.NursingHomes.Find(id); if (nursinghome == null) { return HttpNotFound(); } NursingHomeViewModel nursingHomeViewModel = new NursingHomeViewModel(); nursingHomeViewModel.CategoryItems = new MultiSelectList(db.CategorySets.ToList(), "Id", "Name", nursinghome.CategorySet.Select(x => x.Id)); nursingHomeViewModel.UserItems = new SelectList(db.Users.ToList().OrderBy(u => u.UserName), "Id", "UserName", nursinghome.ApplicationUserId); nursingHomeViewModel.RegionItems = new SelectList(db.Regions.ToList().OrderBy(r => r.Name), "Id", "Name", nursinghome.Region); NursingHomeDto nhDto = new NursingHomeDto(nursinghome, nursingHomeViewModel, db); nhDto.DbObject2ViewModel(); return View(nursingHomeViewModel); } // GET: /NursingHome/Create [Authorize(Roles = "Admin")] public ActionResult Create() { var nursingHome = new NursingHome {Name = "1 Name", RegionId = db.Regions.First().Id}; db.NursingHomes.Add(nursingHome); db.SaveChanges(); return RedirectToAction("Edit", new {nursingHome.Id}); } // GET: /NursingHome/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } NursingHome nursinghome = db.NursingHomes.Find(id); if (nursinghome == null) { return HttpNotFound(); } if ((User.IsInRole("Admin") || nursinghome.ApplicationUserId == User.Identity.GetUserId())) { NursingHomeViewModel nursingHomeViewModel = new NursingHomeViewModel { UserItems = new SelectList( db.Users.ToList().OrderBy(user => user.UserName) .Select(user => new SelectListItem {Text = user.UserName, Value = user.Id.ToString()}), "Value", "Text"), RegionItems = new SelectList( db.Regions.ToList().OrderBy(region => region.Name) .Select(region => new SelectListItem {Text = region.Name, Value = region.Id.ToString()}), "Value", "Text"), CategoryItems = new MultiSelectList(db.CategorySets.ToList(), "Id", "Name", nursinghome.CategorySet.Select(x => x.Id)) }; NursingHomeDto nhDto = new NursingHomeDto(nursinghome, nursingHomeViewModel, db); nhDto.DbObject2ViewModel(); return View(nursingHomeViewModel); } return new HttpStatusCodeResult(HttpStatusCode.Forbidden); } // POST: /NursingHome/Edit/5 // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include = "Id,Name,Street,PostalCode,City,Phone,Fax,EMail,Website,RTName," + "RTAddress,ApplicationUserId,RegionId,Description,IsAlternative," + "SelectedCategoryItems,CapacityShortCare,CapacityDailyCare," + "CapacityLongTimeCare,CapacityAlternativeLivingEnvironment," + "CapacityLongTimeSupport,LongTimeCareI,LongTimeCareII_f,LongTimeCareII_m," + "ShortTimeCare,DailySupport,LongTimeSupportI,LongTimeSupportII_f,LongTimeSupportII_m," + "AlternativeLivingEnvironmentI,AlternativeLivingEnvironmentII_f,AlternativeLivingEnvironmentII_m," + "ShortTimeCareForDate,ApprovedShortTimeCare,ApprovedDailySupport,ApprovedLongTimeCare," + "ApprovedLongTimeSupport,ApprovedAlternativeLivingEnvironment")] NursingHomeViewModel nursingHomeViewModel) { var nursingHome = db.NursingHomes.Find(nursingHomeViewModel.Id); if ((User.IsInRole("Admin") || nursingHome.ApplicationUserId == User.Identity.GetUserId())) { if (ModelState.IsValid) { var latLng = GoogleGeoCode.GeoCodeAddress(string.Format("{0} {1}, {2}", nursingHomeViewModel.PostalCode, nursingHomeViewModel.City, nursingHomeViewModel.Street)); nursingHomeViewModel.Latitude = latLng.Key; nursingHomeViewModel.Longitude = latLng.Value; nursingHomeViewModel.ModifiedDate = DateTime.Now; NursingHomeDto nhDto = new NursingHomeDto(nursingHome, nursingHomeViewModel, db); CheckAvailablePlaces(nhDto, nursingHome); nhDto.ViewModel2DbObject(); db.Entry(nursingHome).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(nursingHomeViewModel); } return new HttpStatusCodeResult(HttpStatusCode.Forbidden); } /// <summary> /// Check Available Places and sends Email if the places has changed. /// </summary> /// <param name="nhDto"></param> /// <param name="nursingHome"></param> private void CheckAvailablePlaces(NursingHomeDto nhDto, NursingHome nursingHome) { var conf = (NotificationConfiguration)WebConfigurationManager.GetSection("notification"); if (conf.Enabled) { StringBuilder body = new StringBuilder(); if (nhDto.freePlacesHasChanged(body)) { SmtpClient sc = new SmtpClient(conf.Smtp.Name, conf.Smtp.Port); MailMessage message = new MailMessage { Subject = "Änderung Anzahl freier Plätze, " + nursingHome.Name, Body = "Die Anzahl der freien Plätze im Pflegeheim " + nursingHome.Name + " hat sich geändert!\n\n" + body, From = new MailAddress(conf.From.Email), IsBodyHtml = true }; if (nursingHome.ApplicationUser != null) message.To.Add(nursingHome.ApplicationUser.Email); foreach (var recipient in conf.Recipients) { message.To.Add(((RecipientElement)recipient).Email); } sc.Send(message); } } } // GET: /NursingHome/Delete/5 public ActionResult Delete(int? id) { NursingHome nursinghome = db.NursingHomes.Find(id); db.NursingHomes.Remove(nursinghome); db.SaveChanges(); return RedirectToAction("Index"); } private enum ViewType { Ltc, Stc, Ds, Lts, Ale, All } private const int TableElements = 15; // 20 [AllowAnonymous] public ActionResult Index(string type, string page) { List<NursingHomeViewModel> filteredNursingHomes; if (User.Identity.IsAuthenticated && !User.IsInRole("Admin") && !User.IsInRole("Auditor")) { filteredNursingHomes = new List<NursingHomeViewModel>(); string userId = User.Identity.GetUserId(); var nursingHomes = db.NursingHomes.Where(m => m.ApplicationUserId == userId); foreach (var home in nursingHomes) { var nursingHomeViewModel = new NursingHomeViewModel(); var nhDto = new NursingHomeDto(home, nursingHomeViewModel, db); nhDto.DbObject2ViewModel(); filteredNursingHomes.Add(nursingHomeViewModel); } } else { switch (type) { case "Ltc": ViewBag.Title = GlobalResources.LongTimeCare; filteredNursingHomes = GetNursingHomes(ViewType.Ltc, true); break; case "Stc": ViewBag.Title = GlobalResources.ShortTimeCare; filteredNursingHomes = GetNursingHomes(ViewType.Stc, true); break; case "Ds": ViewBag.Title = GlobalResources.DailySupport; filteredNursingHomes = GetNursingHomes(ViewType.Ds, true); break; case "Lts": ViewBag.Title = GlobalResources.LongTimeSupport; filteredNursingHomes = GetNursingHomes(ViewType.Lts, true); break; case "Ale": ViewBag.Title = GlobalResources.AlternativeLivingEnvironment; filteredNursingHomes = GetNursingHomes(ViewType.Ale, true); break; default: ViewBag.Title = GlobalResources.AllNursingHomes; filteredNursingHomes = GetNursingHomes(ViewType.All, false); break; } } var onePageOfNursingHomes = filteredNursingHomes.ToPagedList(string.IsNullOrEmpty(page) ? 1 : int.Parse(page), TableElements); ViewBag.OnePageOfNursingHomes = onePageOfNursingHomes; ViewBag.Type = string.IsNullOrEmpty(type) ? "All" : type; return View(filteredNursingHomes); } [AllowAnonymous] public ActionResult Map(string type) { List<NursingHomeViewModel> filteredNursingHomes = null; switch (type) { case "Ltc": ViewBag.Title = GlobalResources.LongTimeCare + " " + GlobalResources.Map; filteredNursingHomes = GetNursingHomes(ViewType.Ltc, false); break; case "Stc": ViewBag.Title = GlobalResources.ShortTimeCare + " " + GlobalResources.Map; filteredNursingHomes = GetNursingHomes(ViewType.Stc, false); break; case "Ds": ViewBag.Title = GlobalResources.DailySupport + " " + GlobalResources.Map; filteredNursingHomes = GetNursingHomes(ViewType.Ds, false); break; case "Lts": ViewBag.Title = GlobalResources.LongTimeSupport + " " + GlobalResources.Map; filteredNursingHomes = GetNursingHomes(ViewType.Lts, false); break; case "Ale": ViewBag.Title = GlobalResources.AlternativeLivingEnvironment + " " + GlobalResources.Map; filteredNursingHomes = GetNursingHomes(ViewType.Ale, false); break; } return View(filteredNursingHomes); } [AllowAnonymous] public ActionResult Region(string type) { List<NursingHomeViewModel> filteredNursingHomes = null; ViewBag.Regions = db.Regions.ToList(); switch (type) { case "Ltc": ViewBag.Title = GlobalResources.LongTimeCare + " " + GlobalResources.Region; filteredNursingHomes = GetNursingHomes(ViewType.Ltc, false); break; case "Stc": ViewBag.Title = GlobalResources.ShortTimeCare + " " + GlobalResources.Region; filteredNursingHomes = GetNursingHomes(ViewType.Stc, false); break; case "Ds": ViewBag.Title = GlobalResources.DailySupport + " " + GlobalResources.Region; filteredNursingHomes = GetNursingHomes(ViewType.Ds, false); break; case "Lts": ViewBag.Title = GlobalResources.LongTimeSupport + " " + GlobalResources.Region; filteredNursingHomes = GetNursingHomes(ViewType.Lts, false); break; case "Ale": ViewBag.Title = GlobalResources.AlternativeLivingEnvironment + " " + GlobalResources.Region; filteredNursingHomes = GetNursingHomes(ViewType.Ale, false); break; } return View(filteredNursingHomes); } private List<NursingHomeViewModel> GetNursingHomes(ViewType type, bool onlyAvailable) { var result = new List<NursingHomeViewModel>(); foreach (var nursingHome in db.NursingHomes) { var nursingHomeViewmmodel = new NursingHomeViewModel(); NursingHomeDto nhDto = new NursingHomeDto(nursingHome, nursingHomeViewmmodel, db); nhDto.DbObject2ViewModel(); ProcessNursingHome(nursingHomeViewmmodel, type); if (type == ViewType.Ale) { if (!nursingHomeViewmmodel.IsAlternative) continue; result.Add(nursingHomeViewmmodel); } else if (onlyAvailable && !nursingHomeViewmmodel.IsAvailable) {} else result.Add(nursingHomeViewmmodel); } return result.OrderBy(x => x.Name).ToList(); } private void ProcessNursingHome(NursingHomeViewModel nh, ViewType type) { switch (type) { case ViewType.Stc: nh.IsAvailable = nh.ShortTimeCare > 0; nh.FreePlaces = nh.ShortTimeCare; break; case ViewType.Ltc: nh.IsAvailable = (nh.LongTimeCareI + nh.LongTimeCareII_m + nh.LongTimeCareII_f) > 0; nh.FreePlaces = (nh.LongTimeCareI + nh.LongTimeCareII_m + nh.LongTimeCareII_f); break; case ViewType.Ds: nh.IsAvailable = nh.DailySupport > 0; nh.FreePlaces = nh.DailySupport; break; case ViewType.Ale: nh.IsAvailable = (nh.AlternativeLivingEnvironmentI + nh.AlternativeLivingEnvironmentII_m + nh.AlternativeLivingEnvironmentII_f) > 0; nh.FreePlaces = (nh.AlternativeLivingEnvironmentI + nh.AlternativeLivingEnvironmentII_m + nh.AlternativeLivingEnvironmentII_f); break; case ViewType.Lts: nh.IsAvailable = (nh.LongTimeSupportI + nh.LongTimeSupportII_m + nh.LongTimeSupportII_f) > 0; nh.FreePlaces = (nh.LongTimeSupportI + nh.LongTimeSupportII_m + nh.LongTimeSupportII_f); break; } } protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); } }}