Esempio n. 1
0
        public ActionResult EditFromSales(SalesContactHelper model)
        {
            var contactId        = Int32.Parse(model.ContactId);
            var contactForUpdate = _db.Contacts.First(c => c.ContactId == 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.ContactEmail))
            {
                contactForUpdate.Email = model.ContactEmail;
            }
            if (!String.IsNullOrEmpty(model.TitleFunction))
            {
                contactForUpdate.Title = model.TitleFunction;
            }
            contactForUpdate.User = User.Identity.Name;
            _db.SaveChanges();

            return(Redirect(Request.UrlReferrer?.ToString()));
        }
Esempio n. 2
0
        public ActionResult CreateFromSales(SalesContactHelper model)
        {
            try
            {
                _db.Contacts.Add(new Contact
                {
                    OrganizationId    = model.OrganizationId,
                    ContactFirstName  = model.FirstName,
                    ContactLastName   = model.LastName,
                    Title             = model.TitleFunction,
                    TelephoneNumber   = model.Telephone,
                    MobilePhoneNumber = model.Mobile,
                    Email             = model.ContactEmail,
                    User        = User.Identity.Name,
                    InsertDate  = DateTime.Now,
                    ContactType = Contact.ContactTypeEnum.Sales,
                });

                _db.SaveChanges();
            }

            // 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 - CreateFromSales", "EntityId: " + model.RelatedEntityId + ", Entity: " + model.EntityType,
                                 @"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));
            }

            return(Redirect(Request.UrlReferrer?.ToString()));
        }
Esempio n. 3
0
        public ActionResult CreateFromSalesLead(SalesContactHelper model)
        {
            var organizationId = (from o in _db.Leads
                                  where o.LeadId == model.RelatedEntityId
                                  select o.RelatedOrganizationId).First().ToString();

            _db.Contacts.Add(new Contact
            {
                OrganizationId    = Int32.Parse(organizationId),
                ContactFirstName  = model.FirstName,
                ContactLastName   = model.LastName,
                Title             = model.TitleFunction,
                TelephoneNumber   = model.Telephone,
                MobilePhoneNumber = model.Mobile,
                Email             = model.ContactEmail,
                User        = User.Identity.Name,
                InsertDate  = DateTime.Now,
                ContactType = Contact.ContactTypeEnum.Sales,
            });

            _db.SaveChanges();

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