Ejemplo n.º 1
0
        public async Task <object> Update([FromBody] UpdateVM model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (!this.IsExistsdb(model.CompanyName))
                    {
                        return(new
                        {
                            success = false,
                            errorMessage = "Update failed"
                        });
                    }
                    var user = db.MemberTable.Where(
                        m => m.CompanyName == model.CompanyName &&
                        m.Name == model.Name && m.Id != model.Id).FirstOrDefault();
                    if (user != null)
                    {
                        //repeated User
                        return(new
                        {
                            success = false,
                            errorMessage = "Repeated User Name"
                        });
                    }
                    user.Name  = model.Name;
                    user.Age   = model.Age;
                    user.Phone = model.Phone;
                    // Update USER
                    db.MemberTable.Attach(user);
                    db.SubmitChanges();
                    return(Ok(new
                    {
                        success = true,
                        errorMessage = "Updated Succeeded"
                    }));
                }
                catch (Exception ex)
                {
                    // return error message if there was an exception
                    return(BadRequest(new { message = ex.Message }));
                }
            }
            // If we got this far, something failed, redisplay form
            var response = new
            {
                success      = false,
                errorMessage = "Update failed"
            };

            return(Ok(response));
        }
 public IActionResult Update(Guid id, [FromBody] UpdateVM model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var client = facade.UpdateClient(id, model.firstname, model.lastname, model.businessName, model.address, model.email, model.primaryPhone);
             return(Ok(client));
         }
         catch (BusinessRuleException ex)
         {
             return(BadRequest(ex.Message));
         }
     }
     else
     {
         return(BadRequest(ModelState.Keys));
     }
 }
Ejemplo n.º 3
0
        public ActionResult ShowUpdateForm(string type, int id, UpdateVM m)
        {
            var entities = new userEntities();

            if (Session["UTYPE"] as string == "ADMIN")
            {
                if (ModelState.IsValid)
                {
                    var db        = new userEntities();
                    var foundUser = db.users.Where(u => u.Id.Equals(id)).FirstOrDefault();

                    foundUser.dob       = m.dob;
                    foundUser.firstname = m.firstname;
                    foundUser.lastname  = m.lastname;

                    db.SaveChanges();

                    if (foundUser.utype == "DOCTOR")
                    {
                        return(RedirectToAction("ManageDoctors", "Admin"));
                    }
                    else if (foundUser.utype == "USER")
                    {
                        return(RedirectToAction("ManagePatients", "Admin"));
                    }
                    else if (foundUser.utype == "ADMIN")
                    {
                        return(RedirectToAction("ManageAdmins", "Admin"));
                    }
                }
                else
                {
                    return(View());
                }
                return(View());
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UpdateProfile(UpdateVM update)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            if (User.Identity.IsAuthenticated)
            {
                AppUser user = await _userManager.FindByNameAsync(User.Identity.Name);

                #region Unique email
                //AppUser existEmail = await _userManager.FindByEmailAsync(update.Email);
                //AppUser existUserName = await _userManager.FindByNameAsync(update.UserName);
                //if (existEmail != null || existUserName != null)
                //{
                //    ModelState.AddModelError("", "Email or UserName already taken!!");
                //    return View(existEmail);
                //}
                #endregion
                #region Photo
                if (update.Photo != null)
                {
                    if (ModelState["Photo"].ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
                    {
                        return(View());
                    }
                    if (!update.Photo.IsImage())
                    {
                        ModelState.AddModelError("Photo", "Zehmet olmasa shekil formati sechin");
                        return(View());
                    }
                    if (update.Photo.MaxLength(2000))
                    {
                        ModelState.AddModelError("Photo", "Shekilin olchusu max 200kb ola biler");
                        return(View());
                    }
                    string path = Path.Combine("assets", "images", "Users");
                    if (user.Image != null)
                    {
                        Helper.DeleteImage(_env.WebRootPath, path, user.Image);
                    }
                    string fileName = await update.Photo.SaveImg(_env.WebRootPath, path);

                    user.Image = fileName;
                }
                #endregion
                #region Resume
                if (update.Resume != null)
                {
                    if (ModelState["Resume"].ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
                    {
                        return(View());
                    }
                    if (!update.Resume.ContentType.Contains("pdf"))
                    {
                        ModelState.AddModelError("Resume", "Zehmet olmasa pdf formati sechin");
                        return(View());
                    }
                    if (update.Resume.MaxLength(3000))
                    {
                        ModelState.AddModelError("Resume", "Pdf olchusu max 3000kb ola biler");
                        return(View());
                    }
                    string path = Path.Combine("assets", "pdf");
                    if (user.Resume != null)
                    {
                        Helper.DeleteImage(_env.WebRootPath, path, user.UserResume);
                    }
                    string fileName = await update.Resume.SaveImg(_env.WebRootPath, path);

                    user.UserResume = fileName;
                }
                #endregion
                user.FullName        = update.FullName;
                user.NormalizedEmail = update.Email;
                user.Email           = update.Email;
                user.Age             = update.Age;
                user.CompanyName     = update.CompanyName;
                user.Location        = update.Location;
                user.ExpectedSalary  = update.ExpectedSalary;
                user.TotalExperience = update.TotalExperience;
                //user.Skills = update.Skills;
                user.Description             = update.Description;
                user.AboutCompanyDescription = update.AboutCompanyDescription;
                user.JobType = update.JobType;
            }
            await _db.SaveChangesAsync();

            //await _signInManager.SignOutAsync();
            return(RedirectToAction("Index", "Home"));
        }