Ejemplo n.º 1
0
        public ActionResult ProfileEdit(int id, RegistrationUpdateViewModel objUpdateEntity)
        {
            var objRegistrationRepository = new RegistrationRepository();
            string fileName = string.Empty;
            string oldFileName = string.Empty;

            if (ModelState.IsValid)
            {
                #region FileUpload

                if (objUpdateEntity.UploadPhoto != null)
                {
                    fileName = Guid.NewGuid().ToString() + Path.GetExtension(objUpdateEntity.UploadPhoto.FileName);
                    oldFileName = objUpdateEntity.PhotoName;
                    objUpdateEntity.PhotoName = fileName;
                }

                #endregion
                objUpdateEntity.FirstName = objUpdateEntity.FirstName.Trim();
                objUpdateEntity.LastName = objUpdateEntity.LastName.Trim();
                objUpdateEntity.PhotoName = objUpdateEntity.PhotoName;
                objUpdateEntity.DateOfBirth = objUpdateEntity.DateOfBirth;
                objUpdateEntity.Location = objUpdateEntity.Location.Trim();
                objUpdateEntity.MobileNumber = objUpdateEntity.MobileNumber.Trim();
                objUpdateEntity.RegistrationId = id;

                var objEntity = new RegistrationViewModel()
                {
                    RegistrationId = objUpdateEntity.RegistrationId,
                    UserId = objUpdateEntity.UserId,
                    FirstName = objUpdateEntity.FirstName,
                    LastName = objUpdateEntity.LastName,
                    PhotoName = objUpdateEntity.PhotoName,

                    DateOfBirth = objUpdateEntity.DateOfBirth,
                    Gender = objUpdateEntity.Gender,

                    Location = objUpdateEntity.Location,
                    MobileNumber = objUpdateEntity.MobileNumber
                };

                objEntity = objRegistrationRepository.Update(RegistrationFlags.UpdateByID.GetHashCode(), objEntity);

                if (objEntity.Result == ResultFlags.Success.GetHashCode())
                {
                    #region FileUpload
                    //delete old file

                    //file name
                    if (objUpdateEntity.UploadPhoto != null)
                    {
                        if (!string.IsNullOrEmpty(objUpdateEntity.UploadPhoto.FileName))
                        {
                            ApplicationHelpers.DeleteFile(Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_USER_PHOTO_PATH), oldFileName));
                        }
                        string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_USER_PHOTO_PATH), fileName);
                        // WebImage.Save()
                        objUpdateEntity.UploadPhoto.SaveAs(path);
                    }

                    #endregion

                    this.Flash("Success", "My Profile updated successfully ");

                    //reload admin profile
                    SessionWrapper.UserAccount = null;
                    AccountRepository objAccountRepository = new AccountRepository();
                    objAccountRepository.SetAccountByUser(objEntity.UserId);

                    return RedirectToAction("Dashboard", "Admin");
                }
                else if (objEntity.Result == ResultFlags.Failure.GetHashCode())
                {
                    this.Flash("Error", "My Profile failed to update");

                }
                else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode())
                {
                    this.Flash("Warning", "It already exist");

                }
            }

            return View(objUpdateEntity);
        }
        public ActionResult Edit(int id, RegistrationUpdateViewModel objUpdateEntity)
        {
            var objRegistrationRepository = new RegistrationRepository();

            if (ModelState.IsValid)
            {

                objUpdateEntity.Name = objUpdateEntity.Name.Trim();

                objUpdateEntity.City = objUpdateEntity.City.Trim();
                objUpdateEntity.MobileNumber = objUpdateEntity.MobileNumber.Trim();
                objUpdateEntity.RegistrationId = id;

             var objEntity=   new RegistrationViewModel()
                    {
                        RegistrationId = objUpdateEntity.RegistrationId,
                        UserId = objUpdateEntity.UserId,
                        Name = objUpdateEntity.Name,

                        DateOfBirth = objUpdateEntity.DateOfBirth,
                        Gender = objUpdateEntity.Gender,

                        City = objUpdateEntity.City,
                        MobileNumber = objUpdateEntity.MobileNumber
                    };

             objEntity = objRegistrationRepository.Update(RegistrationFlags.UpdateByID.GetHashCode(), objEntity);

             if (objEntity.Result == ResultFlags.Success.GetHashCode())
                {
                    this.Flash("success", "Data updated successfully ");

                    return RedirectToAction("Index");
                }
             else if (objEntity.Result == ResultFlags.Failure.GetHashCode())
                {
                    this.Flash("error", "Account failed to update");

                }
             else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode())
                {
                    this.Flash("warning", "It already exist");

                }
            }

            return View(objUpdateEntity);
        }