public ApiResponseModel UpdateGalleryType(GalleryTypeModel galleryTypeModel) { ApiResponseModel apiResponseModel = new ApiResponseModel { Message = "Updated", MessageType = ApiResponseMessageType.success }; if (galleryTypeModel != null) { var _oldData = _db.MstGalleryType.Where(x => x.GalleryTypeId.Equals(galleryTypeModel.GalleryTypeId) && x.IsActive).FirstOrDefault(); if (_oldData != null) { _oldData.BaseUrl = galleryTypeModel.BaseUrl; _oldData.GridSize = galleryTypeModel.GridSize; _oldData.GalleryType = galleryTypeModel.GalleryType; _oldData.ModifiedDate = DateTime.Now; _oldData.ModifiedBy = galleryTypeModel.UserId; _db.Entry(_oldData).State = EntityState.Modified; if (_db.SaveChanges() < 1) { apiResponseModel.Message = "Unable to update."; apiResponseModel.MessageType = ApiResponseMessageType.error; } } } else { apiResponseModel.Message = "Unable to find record"; apiResponseModel.MessageType = ApiResponseMessageType.warning; } return(apiResponseModel); }
public ApiResponseModel BlockUser(UserBlockModel userBlockModel) { ApiResponseModel apiResponseModel = new ApiResponseModel(); var user = _db.MstUsers.Where(x => x.IsActive && x.UserId.Equals(userBlockModel.UserId)).FirstOrDefault(); if (user != null) { user.IsBlocked = userBlockModel.IsBlocked; user.ModifiedDate = DateTime.Now; _db.Entry(user).State = EntityState.Modified; if (_db.SaveChanges() > 0) { apiResponseModel.Message = userBlockModel.IsBlocked ? "Blocked" : "Unblocked"; } else { apiResponseModel.Message = "Unable to block user."; } } else { apiResponseModel.Message = "User not found"; } return(apiResponseModel); }
public bool SaveProfile(UserProfileModel userProfileModel, IHostingEnvironment hostingEnvironment) { string dir = "\\Images\\Users\\"; string path = dir + "User_" + userProfileModel.UserId + ".jpg"; var _webRootPath = string.Empty; if (hostingEnvironment != null) { _webRootPath = hostingEnvironment.WebRootPath; if (userProfileModel.IsImageRemoved) { File.Delete(path); } if (userProfileModel != null && userProfileModel.Photo != null) { path = dir + "User_" + userProfileModel.UserId + userProfileModel.Photo.FileName.Substring(userProfileModel.Photo.FileName.LastIndexOf(".")); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (File.Exists(path)) { File.Delete(path); } using (var stream = new FileStream(_webRootPath + path, FileMode.Create)) { userProfileModel.Photo.CopyTo(stream); } } } var _user = _db.MstUsers.Where(x => x.UserId == userProfileModel.UserId && x.IsActive).FirstOrDefault(); if (_user != null) { _user.Gender = userProfileModel.Gender; _user.ModifiedBy = userProfileModel.UserId; _user.ModifiedDate = DateTime.Now; _db.Entry(_user).State = EntityState.Modified; MstUserDetails mstUserDetails = new MstUserDetails() { CreatedBy = 1, CreatedDate = DateTime.Now, FacebookProfile = userProfileModel.FacebookProfile, InstagramProfile = userProfileModel.InstagramProfile, IsActive = true, UserId = userProfileModel.UserId, Website = userProfileModel.Website, Photo = path }; _db.MstUserDetails.Add(mstUserDetails); } return(_db.SaveChanges() > 0 ? true : false); }