protected async Task <IActionResult> SaveBaseTile(IConfigStore store, BaseTile tile)
        {
            await store.ManipulateConfig(c =>
            {
                if (!string.IsNullOrWhiteSpace(Request.Form["originalName"]))
                {
                    var existing = c.Tiles.FirstOrDefault(t => t.Name == Request.Form["originalName"]);
                    if (existing == null)
                    {
                        TempData.AddError($"Unable to update tile with original name '{Request.Form["originalName"]}'.");
                    }

                    var i = c.Tiles.IndexOf(existing);
                    c.Tiles.RemoveAt(i);
                    c.Tiles.Insert(i, tile);
                }
                else
                {
                    c.Tiles.Add(tile);
                }
            });

            TempData.AddSuccess($"Successfully saved {tile.Type} tile '{tile.Name}'.");

            return(RedirectToAction("Index", "AdminTile"));
        }
Esempio n. 2
0
        public ActionResult Delete(int id)
        {
            ConveyanceInOut convInOut = convInOutRepo.GetOne(id);

            if (convInOut != null)
            {
                try
                {
                    //Delete the record
                    convInOutRepo.DoDelete(convInOut);
                    new RecordDeletedEvent("ConveyanceInOut", convInOut.Id, 0, convInOut.Code, convInOut.Conveyance.Name, null).Raise();
                    TempData.AddInfo(Resources.Messages.DeleteSuccess + " (" + convInOut.Code + "-" + convInOut.Conveyance.Name + ")");
                }
                catch (Exception ex)
                {
                    TempData.AddError(ex.ExMessage());
                    return(RedirectToAction("Edit", new { id = id }));
                }
            }
            else
            {
                TempData.AddError(Resources.Messages.NotFoundData);
            }

            return(RedirectToAction("Index2"));
        }
        public async Task <IActionResult> Settings([FromForm] SystemSettings newSettings)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    newSettings ??= new SystemSettings();
                    newSettings.BaseUri     = newSettings.BaseUri?.TrimEnd('/');
                    newSettings.AccessToken = newSettings.AccessToken?.Trim();
                    await ConfigStore.ManipulateConfig(c => c.Settings = newSettings);

                    ClientFactory.Reset();

                    TempData["check-settings"] = true;

                    return(RedirectToAction("Settings"));
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Saving system settings failed.");
                TempData.AddError("Unable to save system settings. See log output (console) for more information.");
            }
            return(View(newSettings));
        }
        public async Task <IActionResult> DeleteTile([FromQuery] string name)
        {
            var config = await ConfigStore.GetConfigAsync();

            var tile = config.Tiles.FirstOrDefault(t => t.Name == name);

            if (tile == null)
            {
                TempData.AddError($"Could not delete tile with name '{name}' (name not found).");
                return(RedirectToAction("Index"));
            }

            config.Tiles.Remove(tile);

            var layout = config.TileLayout.FirstOrDefault(l => l.Name == name);

            if (layout != null)
            {
                config.TileLayout.Remove(layout);
            }

            await ConfigStore.SaveConfigAsync(config);

            TempData.AddSuccess($"Tile '{name}' was deleted successfully.");

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> ImportTheme([FromForm] IFormFile file)
        {
            if (file == null)
            {
                TempData.AddWarning("No file was uploaded. Please try again.");
                return(RedirectToAction("Themes"));
            }

            string contents;

            using (var sr = new StreamReader(file.OpenReadStream()))
            {
                contents = await sr.ReadToEndAsync();
            }

            try
            {
                var newTheme = JsonConvert.DeserializeObject <Theme>(contents);

                var config = await ConfigStore.GetConfigAsync();

                await ConfigStore.ManipulateConfig(c => c.CurrentTheme = newTheme);

                TempData.AddSuccess($"Successfully imported theme file '{file.FileName}' successfully! <a href=\"/\">Go check out your dashboard!</a>");
            }
            catch
            {
                TempData.AddError("Import file was not a theme file or could not otherwise be imported. Check that the file is not malformed and try again.");
            }

            return(RedirectToAction("Themes"));
        }
        public async Task <IActionResult> Settings([FromForm] SystemSettings newSettings)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    newSettings ??= new SystemSettings();

                    if (newSettings.IsHassIo)
                    {
                        newSettings.BaseUri = "http://hassio/homeassistant";
                    }
                    else
                    {
                        newSettings.BaseUri = newSettings.BaseUri.TrimEnd('/');
                    }
                    await ConfigStore.ManipulateConfig(c => c.Settings = newSettings);

                    TempData["check-settings"] = true;

                    return(RedirectToAction("Settings"));
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Saving system settings failed.");
                TempData.AddError("Unable to save system settings. See log output (console) for more information.");
            }
            return(View(newSettings));
        }
Esempio n. 7
0
        public ActionResult Delete(int id)
        {
            Staying90Day stay = stayRepo.GetOne(id);

            if (stay != null)
            {
                try
                {
                    //Delete the record
                    stayRepo.DoDelete(stay);
                    new RecordDeletedEvent("Staying90Day", stay.Id, 0, stay.Code, stay.Alien.Name.FullName, null).Raise();
                    TempData.AddInfo(Resources.Messages.DeleteSuccess + " (" + stay.Code + "-" + stay.Alien.Name.FullName + ")");
                }
                catch (Exception ex)
                {
                    TempData.AddError(ex.ExMessage());
                    return(RedirectToAction("Edit", new { id = id }));
                }
            }
            else
            {
                TempData.AddError(Resources.Messages.NotFoundData);
            }

            return(RedirectToAction("Index2"));
        }
        public ActionResult Delete(int id, int addRemoveType)
        {
            AddRemoveCrew addRemoveCrew = addRemoveCrewRepo.GetOne(id, addRemoveType);

            if (addRemoveCrew != null)
            {
                try
                {
                    //Delete the record
                    addRemoveCrewRepo.DoDelete(addRemoveCrew);
                    new RecordDeletedEvent("AddRemoveCrew", addRemoveCrew.Id, 0, addRemoveCrew.Code, addRemoveCrew.Alien.Name.FullName, null).Raise();
                    TempData.AddInfo(Resources.Messages.DeleteSuccess + " (" + addRemoveCrew.Code + "-" + addRemoveCrew.Alien.Name.FullName + ")");
                }
                catch (Exception ex)
                {
                    TempData.AddError(ex.ExMessage());
                    return(RedirectToAction("Edit", new { id, addRemoveType }));
                }
            }
            else
            {
                TempData.AddError(Resources.Messages.NotFoundData);
            }

            return(RedirectToAction("Index2", new { addRemoveType }));
        }
        protected async Task <IActionResult> SaveBaseTile([FromRoute] string page, IConfigStore store, BaseTile tile)
        {
            await store.ManipulateConfig(c =>
            {
                if (!string.IsNullOrWhiteSpace(Request.Form["originalName"]))
                {
                    var existing = c[page].Tiles.FirstOrDefault(t => t.Name == Request.Form["originalName"]);
                    if (existing == null)
                    {
                        TempData.AddError($"Unable to update tile with original name '{Request.Form["originalName"]}'.");
                    }

                    var i = c[page].Tiles.IndexOf(existing);
                    if (i > -1)
                    {
                        c[page].Tiles.RemoveAt(i);
                        c[page].Tiles.Insert(i, tile);
                    }
                    else
                    {
                        c[page].Tiles.Add(tile);
                    }
                }
                else
                {
                    c[page].Tiles.Add(tile);
                }
            });

            TempData.AddSuccess($"Successfully saved {tile.Type} tile '{tile.Name}'.<br /><br /><i class=\"info circle icon\"></i><strong>Tip:</strong> If you just added a new tile, you should proceed to <strong><a href=\"/admin/pages/{page}/layout\">edit this page's layout</a></strong>.");

            return(RedirectToAction("Index", "AdminTile", new { page }));
        }
Esempio n. 10
0
        public ActionResult Delete(int id)
        {
            Endorse endorse = endorseRepo.GetOne(id);

            if (endorse != null)
            {
                try
                {
                    //Delete the record
                    endorseRepo.DoDelete(endorse);
                    new RecordDeletedEvent("Endorse", endorse.Id, 0, endorse.Code, endorse.Alien.Name.FullName, null).Raise();
                    TempData.AddInfo(Resources.Messages.DeleteSuccess + " (" + endorse.Code + "-" + endorse.Alien.Name.FullName + ")");
                }
                catch (Exception ex)
                {
                    TempData.AddError(ex.ExMessage());
                    return(RedirectToAction("Edit", new { id = id }));
                }
            }
            else
            {
                TempData.AddError(Resources.Messages.NotFoundData);
            }

            return(RedirectToAction("Index2"));
        }
Esempio n. 11
0
        public ActionResult Delete(int id)
        {
            VisaDetail visa = visaRepo.GetOne(id);

            if (visa != null)
            {
                try
                {
                    //Delete the record
                    visaRepo.DoDelete(visa);
                    new RecordDeletedEvent("VisaDetail", visa.Id, 0, visa.Code, visa.Alien.Name.FullName, null).Raise();
                    TempData.AddInfo(Resources.Messages.DeleteSuccess + " (" + visa.Code + "-" + visa.Alien.Name.FullName + ")");
                }
                catch (Exception ex)
                {
                    TempData.AddError(ex.ExMessage());
                    return(RedirectToAction("Edit", new { id = id }));
                }
            }
            else
            {
                TempData.AddError(Resources.Messages.NotFoundData);
            }

            return(RedirectToAction("Index2"));
        }
        public async Task <IActionResult> Settings()
        {
            var config = await ConfigStore.GetConfigAsync();

            try
            {
                if (TempData["check-settings"] is bool b && b)
                {
                    // This doesn't check if the access token is valid...
                    var inst = await DiscoveryClient.GetDiscoveryInfo();

                    // ... but this does.
                    var entities = await EntityClient.GetEntities();

                    ViewBag.Instance = $"Home Assistant instance: <b>{inst.LocationName} (Version {inst.Version}) [{inst.BaseUrl}]</b>";
                }
            }
            catch (Exception ex)
            {
                await ConfigStore.ManipulateConfig(c => c.Settings.AccessToken = c.Settings.BaseUri = null);

                config = await ConfigStore.GetConfigAsync();

                TempData.Remove(AlertManager.GRP_SUCCESS);
                Logger.LogError(ex, "Invalid system settings entered, or unable to reach Home Assistant with the specified information.");
                TempData.AddError("The settings entered are not valid. HACC is unable to reach your Home Assistant instance. Try your entries again, consult the <a target=\"_blank\" href=\"https://github.com/qJake/HADotNet.CommandCenter/wiki/Initial-System-Setup\">setup guide</a> for help, or check the logs (console) for more information.");

                // Reloads the request showing the error (TempData doesn't commit until a reload).
                return(RedirectToAction("Settings"));
            }

            return(View(config.Settings));
        }
 public async Task <IActionResult> UpdateLayoutSettings(LayoutSettings settings)
 {
     if (ModelState.IsValid)
     {
         TempData.AddSuccess("Saved layout settings successfully!");
         await ConfigStore.ManipulateConfig(c => c.LayoutSettings = settings);
     }
     else
     {
         TempData.AddError("Unable to save layout settings.");
     }
     return(RedirectToAction("Layout"));
 }
Esempio n. 14
0
        private ActionResult doEdit(AddRemoveCrew addRemoveCrew, int addRemoveType, bool?backToSearch = null)
        {
            ToolbarMenuHelpers.SetToolBar(ViewData,
                                          new { Save = "btnSave", New = "Insert", GiveUp = "btnDelete", Close = "Index2" }, "AddRemoveCrew", new { addRemoveType, backToSearch });

            ViewData["AddRemoveType"] = addRemoveType;
            if (addRemoveCrew != null)
            {
                return(View(addRemoveCrew));
            }
            else
            {
                TempData.AddError(Resources.Messages.NotFoundData);
                return(RedirectToAction("Index2", new { addRemoveType }));
            }
        }
        public async Task <IActionResult> ImportConfig([FromForm] IFormFile file)
        {
            try
            {
                if (file == null)
                {
                    TempData.AddWarning("No file was uploaded. Please try again.");
                    return(RedirectToAction("Index"));
                }

                string contents;
                using (var sr = new StreamReader(file.OpenReadStream()))
                {
                    contents = await sr.ReadToEndAsync();
                }

                try
                {
                    var newConfig = JsonConvert.DeserializeObject <ConfigRoot>(contents);
                    newConfig.Settings = null;

                    var config = await ConfigStore.GetConfigAsync();

                    var oldSettings = config.Settings;

                    newConfig.Settings = oldSettings;

                    await ConfigStore.SaveConfigAsync(newConfig);

                    // Ensures arrays are non-null even if no actions are performed.
                    await ConfigStore.ManipulateConfig();

                    TempData.AddSuccess($"Successfully imported system configuration file '{file.FileName}'!");
                }
                catch
                {
                    Logger.LogWarning("File selected was not able to be parsed into a config object. Check file contents and try again.");
                    TempData.AddError("Import file was not a configuration file or could not otherwise be imported. Check that the file is not malformed and try again.");
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Importing system config settings failed.");
                TempData.AddError("Unable to import system configuration. See log output (console) for more information.");
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 16
0
        private ActionResult doEdit(Staying90Day stay)
        {
            ToolbarMenuHelpers.SetToolBar(ViewData,
                                          new { Save = "btnSave", New = "Insert", GiveUp = "btnDelete", Close = "Index2" }, "Stay");

            //ส่งผ่านตัวแปรเพื่อทำ combobox
            //makeReferenceViewData();

            if (stay != null)
            {
                return(View(stay));
            }
            else
            {
                TempData.AddError(Resources.Messages.NotFoundData);
                return(RedirectToAction("Index2"));
            }
        }
Esempio n. 17
0
        private ActionResult doEdit(ConveyanceInOut convInOut, bool?backToSearch = null)
        {
            ToolbarMenuHelpers.SetToolBar(ViewData,
                                          new { Save = "btnSave", New = "Insert", GiveUp = "btnDelete", Close = "Index2" }, "ConveyanceInOut", new { backToSearch });

            //ส่งผ่านตัวแปรเพื่อทำ combobox
            //makeReferenceViewData();

            if (convInOut != null)
            {
                return(View(convInOut));
            }
            else
            {
                TempData.AddError(Resources.Messages.NotFoundData);
                return(RedirectToAction("Index2"));
            }
        }
        public RedirectToRouteResult SetPassword(Guid id, string password)
        {
            var user = _userService.Get(id);

            try
            {
                _passwordService.ChangePassword(user, password);

                var body = string.Format(ResetPasswordBody, new string[] { user.UserName, password, Request.Url.GetLeftPart(UriPartial.Authority) });
                _smtpClient.Send(new MailMessage(ResetPasswordFromAddress, user.Email, ResetPasswordSubject, body));

                TempData.AddInfo(Resources.Messages.ActionSuccess);
            }
            catch (Exception ex)
            {
                TempData.AddError(Resources.Messages.SaveError + ex.ExMessage());
            }
            return(RedirectToAction("Password", new { id }));
        }
Esempio n. 19
0
        public ActionResult Delete(int refTypeId, int id)
        {
            //Find a customer with ProductID equal to the id action parameter
            zz_Reference reference = refRepo.GetOne(id);

            this.refRepo.CurrentUserName = HttpContext.User.Identity.Name;
            if (reference != null)
            {
                try
                {
                    //Delete the record
                    refRepo.DoDelete(reference);
                    new RecordDeletedEvent("Reference", reference.Id, reference.RefTypeId, reference.Code, reference.RefName, null).Raise();
                }
                catch (ApplicationException ex)
                {
                    TempData.AddError(ex.ExMessage());
                }
            }
            return(RedirectToAction("Index", new { refTypeId = refTypeId }));
        }
        public async Task <IActionResult> UpdateLayout()
        {
            var val = Request.Form["tilelayout"][0];

            try
            {
                var layout = JsonConvert.DeserializeObject <List <TileLayout> >(val);

                // Multiply the X and Y by 2 since the preview is at 50%.
                layout.ForEach(l => { l.XPos *= 2; l.YPos *= 2; });

                await ConfigStore.ManipulateConfig(c => c.TileLayout = layout);

                TempData.AddSuccess("Tile layout saved successfully!");
            }
            catch
            {
                TempData.AddError("Unable to read tile layout from page. Cannot write to config file.");
            }

            return(RedirectToAction("Layout"));
        }
        public async Task <IActionResult> SaveTheme([FromForm] Theme newTheme)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var config = await ConfigStore.GetConfigAsync();

                    await ConfigStore.ManipulateConfig(c => c.CurrentTheme = newTheme);

                    TempData.AddSuccess("Saved theme settings successfully!");

                    return(RedirectToAction("Themes"));
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Saving theme settings failed.");
                TempData.AddError("Unable to save theme changes. See log output (console) for more information.");
            }
            return(View("Themes", newTheme));
        }
        public async Task <IActionResult> ImportTheme([FromForm] IFormFile file)
        {
            try
            {
                if (file == null)
                {
                    TempData.AddWarning("No file was uploaded. Please try again.");
                    return(RedirectToAction("Themes"));
                }

                string contents;
                using (var sr = new StreamReader(file.OpenReadStream()))
                {
                    contents = await sr.ReadToEndAsync();
                }

                try
                {
                    var newTheme = JsonConvert.DeserializeObject <Theme>(contents);

                    var config = await ConfigStore.GetConfigAsync();

                    await ConfigStore.ManipulateConfig(c => c.CurrentTheme = newTheme);

                    TempData.AddSuccess($"Successfully imported theme file '{file.FileName}' successfully! <a href=\"/d\" target=\"_blank\">Go check out your dashboard!</a>");
                }
                catch
                {
                    Logger.LogWarning("File selected was not able to be parsed into a theme. Check file contents and try again.");
                    TempData.AddError("Import file was not a theme file or could not otherwise be imported. Check that the file is not malformed and try again.");
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Importing theme settings failed.");
                TempData.AddError("Unable to import theme. See log output (console) for more information.");
            }
            return(RedirectToAction("Themes"));
        }
        public RedirectToRouteResult UsersProfiles(Guid id, string Profile_FirstName, string Profile_LastName,
                                                   string Profile_Position, string Profile_Phone, string Profile_Fax,
                                                   string Profile_Culture, int Profile_PageSize, int Profile_MainScreenHeight)
        {
            var           user    = _userService.Get(id);
            ProfileCommon profile = ProfileCommon.GetProfile(user.UserName);

            if (ModelState.IsValid)
            {
                try
                {
                    profile.FirstName        = Profile_FirstName;
                    profile.LastName         = Profile_LastName;
                    profile.Position         = Profile_Position;
                    profile.Phone            = Profile_Phone;
                    profile.Fax              = Profile_Fax;
                    profile.Culture          = Profile_Culture == "-" ? "" : Profile_Culture.Trim();
                    profile.PageSize         = Profile_PageSize;
                    profile.MainScreenHeight = Profile_MainScreenHeight;
                    profile.Save();

                    TempData.AddInfo(Resources.Messages.SaveSuccess);
                    if (user.UserName == HttpContext.User.Identity.Name)
                    {
                        //Globals.ReadProfileToGlobals(user.UserName, true);
                        ProfileRepository.ClearCurrentProfile();
                    }
                    return(RedirectToAction("UsersProfiles", new { id }));
                }
                catch (Exception ex)
                {
                    TempData.AddError(Resources.Messages.SaveError + ex.ExMessage());
                }
            }
            return(RedirectToAction("UsersProfiles", new { id }));
        }