Exemplo n.º 1
0
 public IActionResult put([FromForm] updatemodel updatemodel)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         Users users = _repository.UpdateUser(updatemodel);
         return(Ok(new { Status = StatusCodes.Status200OK, Message = "success", users }));
     }
     catch (HttpException ex)
     {
         return(new ObjectResult(new { Status = ex.StatusCode, Message = ex.StatusDescription }));
     }
     catch (Exception ex)
     {
         return(new ObjectResult(new { Status = StatusCodes.Status500InternalServerError, Message = ex.Message }));
     }
 }
Exemplo n.º 2
0
        public Users UpdateUser(updatemodel model)
        {
            string ResponesUrl = string.Empty;

            try
            {
                Users userslist = repository.FindByCondition(x => x.Userid == model.Userid).FirstOrDefault();
                if (userslist == null)
                {
                    throw new HttpException((int)HttpStatusCode.NotFound, "Userid Not Found,Please Try Again");
                }
                if (model.FileExist)
                {
                    using (var fileStream = model.ImageUpload.OpenReadStream())
                    {
                        byte[]             fileData         = new byte[model.ImageUpload.Length];
                        string             mimeType         = model.ImageUpload.ContentType;
                        string             strContainerName = "imagecontainer";
                        BlobStorageService objBlobService   = new BlobStorageService();
                        ResponesUrl = objBlobService.UploadFileToBlob(model.ImageUpload.FileName, fileData, mimeType, strContainerName);
                    }
                    userslist.ProfileImg       = ResponesUrl;
                    userslist.LastModifiedDate = DateTime.Now.ToString();
                    repository.Update(userslist);
                    repository.Save();
                }

                return(userslist);
            }
            catch (HttpException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }