Esempio n. 1
0
        public ActionResult Edit(UserModel model)
        {
            UserModel currentModel;
            User user = Context.Users
                .Where(a => a.ID == model.UserId)
                .Single();

            if (!ModelState.IsValid)
            {
                currentModel = user.ToUserEditModel();
                model.BirthDate = currentModel.BirthDate;
                model.Sex = currentModel.Sex;
                model.Username = currentModel.Username;
                model.LegalName = currentModel.LegalName;
                return View("Edit", model);
            }
            try
            {
                DateTime dt;
                user.Alias = model.Alias;
                if (DateTime.TryParse(model.BirthDate, out dt))
                {
                    user.Birthdate = new DateTime?(dt);
                }
                user.Bio = model.Bio;
                user.City = model.City;
                user.Email = model.Email;
                user.FurCode = model.Furcode;
                user.HomePhone = model.HomePhone;
                user.Interests = model.InterestTags;
                user.LastActivityDate = new DateTime?(DateTime.UtcNow);
                user.Messenger1ID = model.Messenger1Id;
                user.Messenger1Type = model.Messenger1Type;
                user.Messenger2ID = model.Messenger2Id;
                user.Messenger2Type = model.Messenger2Type;
                user.Messenger3ID = model.Messenger3Id;
                user.Messenger3Type = model.Messenger3Type;
                user.Messenger4ID = model.Messenger4Id;
                user.Messenger4Type = model.Messenger4Type;
                user.MobilePhone = model.MobilePhone;
                user.Orientation = model.Orientation;
                user.PrivacyLevel = model.PrivacyLevel;
                user.RelationshipStatus = model.RelationshipStatus;
                user.Sex = model.Sex;
                user.Species = model.Species;
                user.SpeciesDetails = model.SpeciesDetails;
                user.StreetAddress1 = model.Address1;
                user.StreetAddress2 = model.Address2;
                user.StreetAddress3 = model.Address3;
                user.ZipCode = model.ZipCode;
                Context.SaveChanges();
                MembershipUser userM = Membership.GetUser(user.ID);
                if (userM != null)
                {
                    userM.Email = model.Email;
                    Membership.UpdateUser(userM);
                }
                return RedirectToAction("Details", new { id = user.ID });
            }
            catch
            {
                currentModel = user.ToUserEditModel();
                model.BirthDate = currentModel.BirthDate;
                model.Sex = currentModel.Sex;
                model.Username = currentModel.Username;
                model.LegalName = currentModel.LegalName;
                return View("Edit", model);
            }
        }
Esempio n. 2
0
        public ActionResult Edit(UserModel model)
        {
            User me = CurrentUser;
            UserModel currentModel;

            if (!ModelState.IsValid)
            {
                currentModel = me.ToEditModel();
                model.BirthDate = currentModel.BirthDate;
                model.Sex = currentModel.Sex;
                model.Username = currentModel.Username;
                model.LegalName = currentModel.LegalName;
                return View("Edit", model);
            }
            try
            {
                DateTime dt;
                me.Alias = model.Alias;
                if (!me.Birthdate.HasValue && DateTime.TryParse(model.BirthDate, out dt))
                {
                    me.Birthdate = new DateTime?(dt);
                }
                me.Bio = model.Bio;
                me.City = model.City;
                me.Email = model.Email;
                me.FurCode = model.Furcode;
                me.HomePhone = model.HomePhone;
                me.Interests = model.InterestTags;
                me.LastActivityDate = new DateTime?(DateTime.UtcNow);
                me.Messenger1ID = model.Messenger1Id;
                me.Messenger1Type = model.Messenger1Type;
                me.Messenger2ID = model.Messenger2Id;
                me.Messenger2Type = model.Messenger2Type;
                me.Messenger3ID = model.Messenger3Id;
                me.Messenger3Type = model.Messenger3Type;
                me.Messenger4ID = model.Messenger4Id;
                me.Messenger4Type = model.Messenger4Type;
                me.MobilePhone = model.MobilePhone;
                me.Orientation = model.Orientation;
                if ((me.PrivacyLevel == 1) || (me.PrivacyLevel < model.PrivacyLevel))
                {
                    me.PrivacyLevel = model.PrivacyLevel;
                }
                me.RelationshipStatus = model.RelationshipStatus;
                if (string.IsNullOrEmpty(me.Sex) && new[] { "Male", "Female" }.Contains(model.Sex, StringComparer.InvariantCulture))
                {
                    me.Sex = model.Sex;
                }
                me.Species = model.Species;
                me.SpeciesDetails = model.SpeciesDetails;
                me.StreetAddress1 = model.Address1;
                me.StreetAddress2 = model.Address2;
                me.StreetAddress3 = model.Address3;
                me.ZipCode = model.ZipCode;
                Context.SaveChanges();
                MembershipUser user = Membership.GetUser();
                user.Email = model.Email;
                Membership.UpdateUser(user);
                return RedirectToAction("Details");
            }
            catch
            {
                currentModel = me.ToEditModel();
                model.BirthDate = currentModel.BirthDate;
                model.Sex = currentModel.Sex;
                model.Username = currentModel.Username;
                model.LegalName = currentModel.LegalName;
                return View("Edit", model);
            }
        }