public IHttpActionResult Save(ProfileBindingModel profile)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var profileModel = Mapper.Map <ProfileBindingModel, BLL.Entities.Profile>(profile);

                    var appUser = User.Identity.GetUserId();
                    profileModel.Id = Guid.Parse(appUser);

                    _profileService.Save(profileModel);

                    //profileModel = _profileService.GetAll().FirstOrDefault(p => p.Id == profileModel.Id);
                    profileModel = _profileService.GetById(profileModel.Id);

                    var profileBM = Mapper.Map <BLL.Entities.Profile, ProfileBindingModel>(profileModel);
                    return(Ok(profileBM));
                }
                catch (Exception ex)
                {
                    var result = ex.Message;
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
            return(Ok(StatusCode(HttpStatusCode.BadRequest)));
        }
Пример #2
0
        public ActionResult EditMyProfile(ProfileBindingModel model)
        {
            var loggedUserId = User.Identity.GetUserId();
            var profile      = Data.Users.Find(loggedUserId);

            if (model.FullName != null)
            {
                profile.FullName = model.FullName;
            }

            if (model.AvatarUrl != null)
            {
                profile.AvatarUrl = model.AvatarUrl;
            }

            if (model.Biography != null)
            {
                profile.Biography = model.Biography;
            }

            if (model.BirthDay != null)
            {
                profile.BirthDay = model.BirthDay;
            }

            if (model.Website != null)
            {
                profile.Website = model.Website;
            }

            this.Data.SaveChanges();
            this.AddNotification("Profile updated!", NotificationType.SUCCESS);

            return(RedirectToAction("MyProfile", "Profile"));
        }
 public IHttpActionResult Delete(Guid id)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var profileBindingModel = new ProfileBindingModel()
             {
                 Id = id
             };
             var profileModel = Mapper.Map <ProfileBindingModel, BLL.Entities.Profile>(profileBindingModel);
             _profileService.Delete(profileModel.Id);
             return(Ok());
         }
         catch (Exception ex)
         {
             var result = ex.Message;
         }
     }
     else
     {
         return(BadRequest(ModelState));
     }
     return(Ok(StatusCode(HttpStatusCode.BadRequest)));
 }