Ejemplo n.º 1
0
        public SystemEmailDto UpdateSystemEmail(SystemEmailDto model)
        {
            try
            {
                var oldSystemEmail     = _context.systememails.FirstOrDefault(x => x.Id == model.Id);
                var updatedSystemEmail = Mapper.Map <systememail>(model);
                updatedSystemEmail.Modified   = DateTime.Now;
                updatedSystemEmail.ModifiedBy = model.ModifiedBy;
                updatedSystemEmail.Created    = oldSystemEmail.Created;
                updatedSystemEmail.CreatedBy  = oldSystemEmail.CreatedBy;



                _context.Entry(oldSystemEmail).CurrentValues.SetValues(updatedSystemEmail);
                _context.SaveChanges();

                return(model);
            }
            catch (DbEntityValidationException ex)
            {
                var errorMsg = EisHelper.ParseDbEntityValidationException(ex);
                _logger.LogError(LogEntryType.VendorProductService, errorMsg, ex.StackTrace);
                throw ex;
            }
            catch (Exception ex)
            {
                _logger.LogError(LogEntryType.VendorProductService, EisHelper.GetExceptionMessage(ex), ex.StackTrace);
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public SystemEmailDto CreateSystemEmail(SystemEmailDto model)
        {
            try
            {
                var systemEmail = Mapper.Map <systememail>(model);
                systemEmail.Created    = DateTime.UtcNow;
                systemEmail.CreatedBy  = model.ModifiedBy;
                systemEmail.ModifiedBy = null;

                _context.systememails.Add(systemEmail);
                _context.SaveChanges();
                model.Id = systemEmail.Id;

                return(model);
            }
            catch (DbEntityValidationException ex)
            {
                var errorMsg = EisHelper.ParseDbEntityValidationException(ex);
                _logger.LogError(LogEntryType.VendorService, errorMsg, ex.StackTrace);
                throw ex;
            }
            catch (Exception ex)
            {
                _logger.LogError(LogEntryType.VendorService, EisHelper.GetExceptionMessage(ex), ex.StackTrace);
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public ActionResult Save(int id, SystemEmailDto model)
        {
            // create view bag first for the vendors
            populateSystemEmailViewBag();
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Values.SelectMany(e => e.Errors.Select(x => x.ErrorMessage));
                ModelState.AddModelError("", string.Join("<br/>", errors));
                return(View("create", model));
            }

            if (_systemEmailsService.IsEmailExist(id, model.EmailAddress))
            {
                if (id <= 0)
                {
                    ModelState.AddModelError("", "Email address already exists");
                    return(View("create", model));
                }
                else
                {
                    ModelState.AddModelError("", "Email address already exists");
                    return(View("edit", model));
                }
            }

            // save the message template
            model.ModifiedBy = User.Identity.Name;
            if (id == 0)
            {
                model = _systemEmailsService.CreateSystemEmail(model);
            }
            else
            {
                model = _systemEmailsService.UpdateSystemEmail(model);
            }

            TempData["Message"] = "Changes have been successfully saved!";
            return(RedirectToAction("edit", new { id = model.Id }));
        }