//[Authorize(Roles = "Координатор ПСР")] public ActionResult <Target> UpdateTarget(int id, TargetUpdateDto targetUpdateDto) { var target = _targetRepository.GetById(id); if (target == null) { return(NotFound()); } _mapper.Map(targetUpdateDto, target); _targetRepository.Update(target); //Best practice _targetRepository.SaveChanges(); _notificationHub.Clients.All.SendAsync("SendMessage", "TargetUpdated"); _notificationHub.Clients.All.SendAsync("Notification", "Цель " + target.Title + " обновлена."); return(NoContent()); }
public IActionResult Edit(TargetUpdateDto model) { if (!ModelState.IsValid) { return(View(model)); } model.UserId = model.UserId = GetCurrentUser().Result.Id; model.LastModified = DateTime.Now; var obj = _mapper.Map <Target>(model); try { _targetService.Update(obj); _customLogger.Information("Updated Target : " + obj.Name); return(RedirectToAction("Index")); } catch (Exception e) { _customLogger.Error("TargetController | Update Target Error..." + e.Message.ToString()); } return(View(model)); }