Exemplo n.º 1
0
        public ActionResult SaveOpeningHoursInfo(SystemViewModels.OpeningHours openHours)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var userName = User.Identity.GetUserName();

                    OpeningHoursInfoDTO openHoursDTO = new OpeningHoursInfoDTO();

                    openHoursDTO = SetHoursAndMinutes(openHours);
                    openHoursDTO.ClosedAnyway          = openHours.ClosedAnyway;
                    openHoursDTO.InfoTextForClosedPage = openHours.InfoTextForClosedPage;

                    //Days
                    var daysListDTO = new List <string>();
                    foreach (var day in openHours.ClosedDaysList)
                    {
                        if (day.Selected)
                        {
                            daysListDTO.Add(day.NameEnglish);
                        }
                    }
                    openHoursDTO.ClosedDays = daysListDTO;

                    _portalAdminService.SparaOppettider(openHoursDTO, userName);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    ErrorManager.WriteToErrorLog("SystemController", "SaveOpeningHoursInfo", e.ToString(), e.HResult, User.Identity.Name);
                    var errorModel = new CustomErrorPageModel
                    {
                        Information  = "Ett fel inträffade när information om öppettider skulle sparas.",
                        ContactEmail = ConfigurationManager.AppSettings["ContactEmail"],
                    };
                    return(View("CustomError", errorModel));
                }
                return(RedirectToAction("GetOpeningHours"));
            }

            //var x = Server.HtmlEncode(openHours.InfoTextForClosedPage);
            return(RedirectToAction("GetOpeningHours"));
        }