示例#1
0
        public async Task <IActionResult> EditFeatureConfirm(AdditionalFeaturesViewModel model)
        {
            ApplicationUser user = null;
            string          nvm;

            if (User.Identity.IsAuthenticated)
            {
                user = await userManager.FindByNameAsync(User.Identity.Name);

                model.UserId = user.Id;
            }
            if (!ModelState.IsValid)
            {
                nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Wrong_Values, contentRootPath);
                return(RedirectToAction("EditFeature", new { model.Id, notification = nvm }));
            }

            try
            {
                var entity = dbAdditionalFeatures.FindById(model.Id);
                entity.Name        = model.Name;
                entity.LatinName   = model.LatinName;
                entity.Description = model.Description;
                entity.Status      = model.Status;
                entity.UserId      = model.UserId;

                dbAdditionalFeatures.Update(entity);

                nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Success_Update, contentRootPath);
                return(RedirectToAction("ShowFeature", new { notification = nvm }));
            }
            catch (Exception)
            {
                nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Failed_Operation, contentRootPath);
                return(RedirectToAction("EditFeature", new { model.Id, notification = nvm }));
            }
        }
示例#2
0
        public async Task <IActionResult> InsertFeatureConfirm(AdditionalFeaturesViewModel model)
        {
            ApplicationUser user = null;
            string          nvm;

            if (User.Identity.IsAuthenticated)
            {
                user = await userManager.FindByNameAsync(User.Identity.Name);

                model.UserId = user.Id;
            }
            if (!ModelState.IsValid)
            {
                nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Wrong_Values, contentRootPath);
                return(RedirectToAction("InsertFeature", new { notification = nvm }));
            }
            try
            {
                AdditionalFeatures additionalFeatures = new AdditionalFeatures()
                {
                    Name        = model.Name,
                    LatinName   = model.LatinName,
                    Description = model.Description,
                    UserId      = model.UserId,
                    RegDateTime = DateTime.Now,
                    Status      = model.Status,
                };
                dbAdditionalFeatures.Insert(additionalFeatures);
                nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Success_Insert, contentRootPath);
                return(RedirectToAction("InsertFeature", new { notification = nvm }));
            }
            catch (Exception)
            {
                nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Failed_Operation, contentRootPath);
                return(RedirectToAction("InsertFeature", new { notification = nvm }));
            }
        }