public HttpResponseMessage updateUserDetails(UpdateUserRequestJSON ureq) { req = Request; if (ureq == null) { return(Utils.CreateEmptyErrorResponse(req)); } if (string.IsNullOrWhiteSpace(ureq.userId.ToString())) { return(Utils.CreateErrorResponse(req, "userId is required")); } //if (users.checkDuplicateEmail(ureq.email)) //{ // return Utils.CreateErrorResponse(req, "email already exists. Please update to a different one."); //} return(Utils.CreateSuccessResponse(req, users.updateUserDetails(ureq))); }
public UpdateUserResponseJSON updateUserDetails(UpdateUserRequestJSON req) { using (MovieEntities db = new MovieEntities()) { var query = db.Users.Where(x => x.Users_ID == req.userId).FirstOrDefault(); if (query != null) { query.address = !string.IsNullOrWhiteSpace(req.address) ? req.address : null; query.ccexpiration = !string.IsNullOrWhiteSpace(req.ccexpiration) ? req.ccexpiration : null; query.ccNo = !string.IsNullOrWhiteSpace(req.ccNo) ? req.ccNo : null; query.city = !string.IsNullOrWhiteSpace(req.city) ? req.city : null; query.country = !string.IsNullOrWhiteSpace(req.country) ? req.country : null; query.cvc = !string.IsNullOrWhiteSpace(req.cvc) ? req.cvc : null; //query.email = !string.IsNullOrWhiteSpace(req.email) ? req.email : null; query.firstName = !string.IsNullOrWhiteSpace(req.firstName) ? req.firstName : null; query.lastName = !string.IsNullOrWhiteSpace(req.lastName) ? req.lastName : null; query.state = !string.IsNullOrWhiteSpace(req.state) ? req.state : null; query.zipcode = !string.IsNullOrWhiteSpace(req.zipcode) ? req.zipcode : null; if (!string.IsNullOrWhiteSpace(req.password)) { string salt = query.salt; string hashedpassword = ComputeHash(salt, req.password); query.passwordHash = hashedpassword; } query.createdDate = DateTime.UtcNow; db.SaveChanges(); } if (req.SocialMediaLogins.Count > 0) { // Delete existing and insert from UsersSocialMedia var result = (from r in db.UsersSocialMedias where r.Users_ID == req.userId select r).ToList(); if (result.Count() > 0) { foreach (UsersSocialMedia p in result) { db.UsersSocialMedias.Remove(p); } db.SaveChanges(); } // Insert foreach (var item in req.SocialMediaLogins) { UsersSocialMedia usm = new UsersSocialMedia(); usm.network = item.network; usm.Users_ID = req.userId; usm.socialMediaAccessToken = item.socialMediaAccessToken; usm.socialMediaUserId = item.socialMediaUserId; db.UsersSocialMedias.Add(usm); db.SaveChanges(); } } } // return whole user object except password. UserResponseJSON usr = getUserDetails(req.userId); UpdateUserResponseJSON res = new UpdateUserResponseJSON(); res.address = usr.address; res.ccexpiration = usr.ccexpiration; res.ccNo = usr.ccNo; res.city = usr.city; res.country = usr.country; res.createdDate = usr.createdDate; res.cvc = usr.cvc; res.email = usr.email; res.firstName = usr.firstName; res.lastName = usr.lastName; res.SocialMediaLogins = usr.SocialMediaLogins; res.state = usr.state; res.zipcode = usr.zipcode; return(res); }