예제 #1
0
 public virtual ActionResult Edit(int id, int clientId)
 {
     var context = ModelFactory.GetUnitOfWork();
     var mRepo = ModelFactory.GetRepository<IMemberRepository>(context);
     var lRepo = ModelFactory.GetRepository<ILocalisationRepository>(context);
     var client = mRepo.Get(clientId);
     if (client == null)
     {
         return View(MVC.Shared.Views.Error);
     }
     var innerModel = new ProfilFormViewModel { Member = client };
     return View(MVC.Backoffice.Client.Views.Add, new LocalisationModel<ProfilFormViewModel> { InnerModel = innerModel, LocalisationModelId = id });
 }
예제 #2
0
        public virtual ActionResult Edit(ProfilFormViewModel model)
        {
            var member = model.Member;
            var id = WebHelper.GetIdentityId(User.Identity);
            if (id == 0)
                return View(MVC.Shared.Views.Error);
            member.MemberId = id;
            if (ModelState.IsValid)
            {
                var context = ModelFactory.GetUnitOfWork();
                var mRepo = ModelFactory.GetRepository<IMemberRepository>(context);
                try
                {
                    //upload images and set image paths
                    foreach (string name in Request.Files)
                    {
                        try
                        {
                            var postedFile = Request.Files[name];
                            if (postedFile == null || string.IsNullOrEmpty(postedFile.FileName))
                                continue;
                            var uploadedFileName = this.UploadFile(postedFile, MiscHelpers.ImageSize.MemberAvatar, Member.AvatarFolder);
                            switch (name)
                            {
                                case "Avatar":
                                    member.MemberMainData.Avatar = uploadedFileName;
                                    break;
                                default:
                                    break;
                            }
                        }
                        catch (Exception ex)
                        {
                            ModelState.AddModelError("", ex.Message);
                        }
                    }
                    var m = mRepo.Get(id);
                    UpdateModel(m, "Member");
                    if (!string.IsNullOrEmpty(member.MemberMainData.Avatar))
                        m.MemberMainData.Avatar = member.MemberMainData.Avatar;

                    context.Commit();

                    TempData[MiscHelpers.TempDataConstants.Info] = Worki.Resources.Views.Profile.ProfileString.ProfilHaveBeenEdit;

                    return RedirectToAction(MVC.Dashboard.Home.Index());
                }
                catch (Exception ex)
                {
                    _Logger.Error("EditProfil", ex);
                    context.Complete();
                    ModelState.AddModelError("EditProfil", ex);
                }
            }
            return View(new ProfilFormViewModel { Member = member });
        }