public ServiceResult SaveTask(ObjTask obj) { try { var task = Map(obj); _taskRepository.Insert(task); _taskRepository.SaveChanges(); //if (obj.RootType == RootTypes.Client) //{ // var client = _clientRepository.Get(obj.RootId); // client.Credit += obj.Cost * CurrencyConverter.ConvertValute(obj.Currency, CurrencyType.Rub); // _clientRepository.Update(client); // _clientRepository.SaveChanges(); //} return(ServiceResult.SuccessResult(task.Id)); } catch (Exception ex) { _Logger.LogError(ex.ToString()); return(ServiceResult.ErrorResult("Ошибка сохранения задачи")); } }
private void UpdateMap(Task task, ObjTask obj) { task.Title = obj.Title; task.Description = obj.Description; task.StatusId = obj.StatusId; task.CompeteProcent = obj.CompeteProcent; task.DeadLine = obj.DeadLine; task.TaskTypeId = obj.TaskTypeId; }
public IActionResult AddTask(ObjTask obj) { var result = _taskService.SaveTask(obj); if (result.Success) { return(Json(_taskService.GetTaskList(obj.RootId, obj.RootType))); } return(Json(result)); }
public IActionResult TaskAdd(ObjTask obj) { var result = _taskService.SaveTask(obj); if (result.Success) { return(RedirectToActionOk("Details", "Tasks", new { id = result.Id }, "Задача добавлена")); } return(RedirectToActionError("TaskAdd", "Ошибка сохранения задачи")); }
public IActionResult EditTask(ObjTask obj) { var result = _taskService.EditTask(obj); if (result.Success) { return(RedirectToActionOk("Details", "Tasks", new { id = result.Id }, "Задача добавлена")); } return(RedirectToActionError("Details", "Ошибка редактирования задачи")); }
private Task Map(ObjTask obj) { return(new Task { Id = obj.Id, RootId = obj.RootId, RootType = obj.RootType, Title = obj.Title, Description = obj.Description, StatusId = obj.StatusId, CompeteProcent = obj.CompeteProcent, DeadLine = obj.DeadLine, TaskTypeId = obj.TaskTypeId, UserId = obj.UserId, }); }
public ServiceResult EditTask(ObjTask obj) { try { var task = _taskRepository.Get(obj.Id); UpdateMap(task, obj); _taskRepository.Update(task); _taskRepository.SaveChanges(); //if (obj.RootType == RootTypes.Client) //{ // var client = _clientRepository.Get(obj.RootId); // client.Credit += (obj.Cost * CurrencyConverter.ConvertValute(obj.Currency, CurrencyType.Rub)) - // (task.Cost * CurrencyConverter.ConvertValute(task.Currency, CurrencyType.Rub)); // _clientRepository.Update(client); // _clientRepository.SaveChanges(); //} return(ServiceResult.SuccessResult(obj.Id)); } catch (Exception ex) { _Logger.LogError("Edit Task error TaskId = {0} : {1}", obj.Id, ex); return(ServiceResult.ErrorResult("Ошибка при сохранении задачи")); } }