//PUT api/Passwords/5 public IHttpActionResult Put(int id, [FromBody] PasswordVM password) { //check if the password id and the id match if (password is null) { return(BadRequest(ErrorMsg.ItemDoesNotExist(TypeOfItems.Password))); } if (id != password.Id) { return(BadRequest(ErrorMsg.InvalidIdMatchingWith(TypeOfItems.Password))); } if (id <= 0) { return(BadRequest(ErrorMsg.InvalidId)); } //check is model is valid var isModelValid = password.IsModelValid(); if (!string.IsNullOrEmpty(isModelValid)) { return(BadRequest(isModelValid)); } //get current user id and modify it string userId = User.Identity.GetUserId(); Password passwordToBeModified = db.Passwords.FirstOrDefault(w => w.Id == id && w.UserId == userId); if (passwordToBeModified is null) { return(BadRequest(ErrorMsg.ItemNotFound(TypeOfItems.Password))); } //modify it passwordToBeModified.ModifyTo(password); db.SaveChanges(); return(Ok()); }
//PUT api/Wifi/5 public IHttpActionResult Put(int id, [FromBody] WifiVM wifi) { //check if the wifi and the id match if (wifi is null) { return(BadRequest(ErrorMsg.ItemDoesNotExist(TypeOfItems.Wifi))); } if (id != wifi.Id) { return(BadRequest(ErrorMsg.InvalidIdMatchingWith(TypeOfItems.Wifi))); } if (id <= 0) { return(BadRequest(ErrorMsg.InvalidId)); } //check if wifi is valid var isModelValid = wifi.IsModelValid(); if (!string.IsNullOrEmpty(isModelValid)) { return(BadRequest(isModelValid)); } //get current user id and modify wifi string userId = User.Identity.GetUserId(); Wifi wifiToBeModified = db.Wifis.FirstOrDefault(w => w.Id == id && w.UserId == userId); if (wifiToBeModified is null) { return(BadRequest(ErrorMsg.ItemNotFound(TypeOfItems.Wifi))); } wifiToBeModified.ModifyTo(wifi); db.SaveChanges(); return(Ok()); }
public IHttpActionResult Put(int id, [FromBody] PaymentCardVM item) { if (item is null) { return(BadRequest(ErrorMsg.ItemDoesNotExist(TypeOfItems.PaymentCard))); } if (id != item.Id) { return(BadRequest(ErrorMsg.InvalidIdMatchingWith(TypeOfItems.PaymentCard))); } if (id <= 0) { return(BadRequest(ErrorMsg.InvalidId)); } var isModelValid = item.IsModelValid(); if (!string.IsNullOrEmpty(isModelValid)) { return(BadRequest(isModelValid)); } string userId = User.Identity.GetUserId(); PaymentCard cardToBeModified = db.PaymentCards.FirstOrDefault(w => w.Id == id && w.UserId == userId); if (cardToBeModified is null) { return(BadRequest(ErrorMsg.ItemNotFound(TypeOfItems.PaymentCard))); } cardToBeModified.ModifyTo(item); db.SaveChanges(); return(Ok()); }
//PUT api/Notes/5 public IHttpActionResult Put(int id, [FromBody] NoteVM note) { if (note is null) { return(BadRequest(ErrorMsg.ItemDoesNotExist(TypeOfItems.Note))); } if (id != note.Id) { return(BadRequest(ErrorMsg.InvalidIdMatchingWith(TypeOfItems.Note))); } if (id <= 0) { return(BadRequest(ErrorMsg.InvalidId)); } var isModelValid = note.IsModelValid(); if (!string.IsNullOrEmpty(isModelValid)) { return(BadRequest(isModelValid)); } string userId = User.Identity.GetUserId(); Note noteToBeModified = db.Notes.FirstOrDefault(w => w.Id == id && w.UserId == userId); if (noteToBeModified is null) { return(BadRequest(ErrorMsg.ItemNotFound(TypeOfItems.Note))); } noteToBeModified.ModifyTo(note); db.SaveChanges(); return(Ok()); }