예제 #1
0
        public ActionResult EditFromDelivery(DeliveryContactHelper model)
        {
            var contactForUpdate = _db.Contacts.First(c => c.ContactId == model.ContactId);

            if (!String.IsNullOrEmpty(model.FirstName))
            {
                contactForUpdate.ContactFirstName = model.FirstName;
            }
            if (!String.IsNullOrEmpty(model.LastName))
            {
                contactForUpdate.ContactLastName = model.LastName;
            }
            if (!String.IsNullOrEmpty(model.Telephone))
            {
                contactForUpdate.TelephoneNumber = model.Telephone;
            }
            if (!String.IsNullOrEmpty(model.Mobile))
            {
                contactForUpdate.MobilePhoneNumber = model.Mobile;
            }
            if (!String.IsNullOrEmpty(model.Email))
            {
                contactForUpdate.Email = model.Email;
            }
            if (!String.IsNullOrEmpty(model.TitleFunction))
            {
                contactForUpdate.Title = model.TitleFunction;
            }

            contactForUpdate.UpdateDate = DateTime.Now;
            contactForUpdate.User       = User.Identity.Name;
            _db.SaveChanges();

            return(RedirectToAction("Details", "Delivery", new { area = "HelpDesk", id = model.TicketId, receiverId = model.ReceiverId }));
        }
예제 #2
0
        public ActionResult CreateFromDelivery(DeliveryContactHelper model)
        {
            try
            {
                _db.Contacts.Add(new Contact
                {
                    OrganizationId    = model.ReceiverId,
                    ContactFirstName  = model.FirstName,
                    ContactLastName   = model.LastName,
                    Title             = model.TitleFunction,
                    TelephoneNumber   = model.Telephone,
                    MobilePhoneNumber = model.Mobile,
                    Email             = model.Email,
                    User        = User.Identity.Name,
                    InsertDate  = DateTime.Now,
                    ContactType = Contact.ContactTypeEnum.Delivery,
                });

                _db.SaveChanges();

                return(Redirect(Request.UrlReferrer?.ToString()));
            }
            // TO DO: This catch part throws DbEntityValidationException in first foreach... I need to check why...
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    _db.LogError.Add(new LogError
                    {
                        Method         = @"Contact - CreateFromDelivery",
                        Parameters     = @"Id = " + model.ReceiverId + @" FirstName = '" + model.FirstName + @"' LastName = '" + model.LastName + @"' TelephoneNumber = '" + model.Telephone + @"' MobilePhoneNumber = '" + model.Mobile + @"' Email = '" + model.Email + @"' User = '******'",
                        Message        = @"Entity of type '" + eve.Entry.Entity.GetType().Name + @"' in state '" + eve.Entry.State + @"' has following validation errors",
                        InnerException = "",
                        Request        = "",
                        User           = User.Identity.Name,
                        InsertDate     = DateTime.Now
                    });
                    _db.SaveChanges();
                    foreach (var ve in eve.ValidationErrors)
                    {
                        _db.LogError.Add(new LogError
                        {
                            Method         = @"Contact - CreateFromDelivery",
                            Parameters     = "",
                            Message        = "Property " + ve.PropertyName + " Error " + ve.ErrorMessage,
                            InnerException = "",
                            Request        = "",
                            User           = User.Identity.Name,
                            InsertDate     = DateTime.Now
                        });
                        _db.SaveChanges();
                    }
                }
                throw;
            }
        }
예제 #3
0
        public ActionResult CreateFromDelivery(DeliveryContactHelper model)
        {
            try
            {
                _db.Contacts.Add(new Contact
                {
                    OrganizationId    = model.ReceiverId,
                    ContactFirstName  = model.FirstName,
                    ContactLastName   = model.LastName,
                    Title             = model.TitleFunction,
                    TelephoneNumber   = model.Telephone,
                    MobilePhoneNumber = model.Mobile,
                    Email             = model.Email,
                    User        = User.Identity.Name,
                    InsertDate  = DateTime.Now,
                    ContactType = Contact.ContactTypeEnum.Delivery,
                });

                _db.SaveChanges();

                return(Redirect(Request.UrlReferrer?.ToString()));
            }

            // We are catching the error which validates the Entity status.
            // On this method we will maybe have wrong e-mail address enteres in the first place and the validation will break.
            catch (DbEntityValidationException dbeve)
            {
                string dbValidationMessages = string.Empty;

                foreach (var err in dbeve.EntityValidationErrors)
                {
                    foreach (var mes in err.ValidationErrors)
                    {
                        dbValidationMessages += mes.ErrorMessage + "/" + mes.PropertyName + ",";
                    }
                }

                _helper.LogError(@"Contact - CreateFromDelivery", "EntityId: " + model.TicketId + ", Entity: Delivery",
                                 @"Prilikom kreiranja kontakta javila se greška: " + dbeve.Message, "Rezultati validacije: " + dbValidationMessages, string.Empty, User.Identity.Name);

                var errorModel = new ErrorModelHelper()
                {
                    ErrorTitle             = @"Greška validacije",
                    ErrorDescription       = @"Prilikom kreiranja kontakta javila se greška: " + dbeve.Message,
                    ErrorArguments         = dbValidationMessages,
                    ErrorException         = dbeve,
                    ErrorSuggestedSolution = @"Molimo pokušajte ispraviti pogrešno unesene argumente!"
                };

                return(View("ErrorNew", errorModel));
            }
        }