public Task UpdateEmployees(int?id, EmployeesDataModel model) { return(Task.Run(() => { Employee employee = null; if (id.HasValue) { employee = _dbcontext.Employees.FirstOrDefault(o => o.Id == id); if (employee == null) { throw new NotFindException("Сотрудник не найден"); } } else { employee = new Employee(); } if (_companiesSrvice.GetCompany(model.CompanyId) == null) { throw new NotFindException("Компания не найдена"); } employee.Fio = model.Fio; employee.Number = model.Number; employee.CompanyId = model.CompanyId; employee.Address = model.Address; employee.BirthDay = model.BirthDay; _dbcontext.Employees.Update(employee); _dbcontext.SaveChanges(); })); }
public EmployeesDataModel GetAllEmployeesDataModel() { EmployeesDataModel tempDataModel = _fiefService.EmployeesList[0]; int prospectorBase = 0; int prospectorLuxury = 0; List <EmployeeModel> tempEmployeesList = new List <EmployeeModel>(); tempDataModel.CalculateTotal = false; tempDataModel.Falconer = 0; tempDataModel.Bailiff = 0; tempDataModel.Herald = 0; tempDataModel.Hunter = 0; tempDataModel.Physician = 0; tempDataModel.Scholar = 0; tempDataModel.Cupbearer = 0; tempDataModel.Prospector = 0; for (int x = 1; x < _fiefService.EmployeesList.Count; x++) { tempDataModel.Falconer += _fiefService.EmployeesList[x].Falconer; tempDataModel.Bailiff += _fiefService.EmployeesList[x].Bailiff; tempDataModel.Herald += _fiefService.EmployeesList[x].Herald; tempDataModel.Hunter += _fiefService.EmployeesList[x].Hunter; tempDataModel.Physician += _fiefService.EmployeesList[x].Physician; tempDataModel.Scholar += _fiefService.EmployeesList[x].Scholar; tempDataModel.Cupbearer += _fiefService.EmployeesList[x].Cupbearer; tempDataModel.Prospector += _fiefService.EmployeesList[x].Prospector; prospectorBase += _fiefService.EmployeesList[x].BaseProspector; prospectorLuxury += _fiefService.EmployeesList[x].LuxuryProspector; tempEmployeesList.AddRange(_fiefService.EmployeesList[x].EmployeesCollection); } tempDataModel.BaseProspector = prospectorBase; tempDataModel.LuxuryProspector = prospectorLuxury; List <EmployeeModel> employeeList = tempEmployeesList .GroupBy(so => new { Name = so.PersonName, so.BaseCost, so.LuxuryCost }) .Select(g => new EmployeeModel { PersonName = g.Key.Name, BaseCost = g.Key.BaseCost, LuxuryCost = g.Key.LuxuryCost, Number = g.Sum(so => so.Number) }) .ToList(); tempDataModel.EmployeesCollection = new ObservableCollection <EmployeeModel>(employeeList); tempDataModel.CalculateTotal = true; tempDataModel.UpdateTotalCosts(); return(tempDataModel); }
public async Task <ActionResult> AddCompany(EmployeesDataModel model, [FromServices] IResultStatus result) { try { await _employeeInterface.UpdateEmployees(null, model); result.status = "ok"; return(Ok(result)); } catch (NotFindException ex) { result.status = "error"; result.message = ex.Message; return(NotFound(result)); } catch { result.status = "error"; result.message = "Внутренняя ошибка"; return(StatusCode(500)); } }
public void SetDataModel(IDataModelBase dataModel, int index) { if (dataModel != null) { if (dataModel.GetType() == typeof(InformationDataModel)) { InformationDataModel tempDataModel = (InformationDataModel)dataModel; _fiefService.InformationList[index] = (InformationDataModel)tempDataModel.Clone(); } else if (dataModel.GetType() == typeof(ArmyDataModel)) { ArmyDataModel tempDataModel = (ArmyDataModel)dataModel; _fiefService.ArmyList[index] = (ArmyDataModel)tempDataModel.Clone(); } else if (dataModel.GetType() == typeof(EmployeesDataModel)) { EmployeesDataModel tempDataModel = (EmployeesDataModel)dataModel; _fiefService.EmployeesList[index] = (EmployeesDataModel)tempDataModel.Clone(); } else if (dataModel.GetType() == typeof(ManorDataModel)) { ManorDataModel tempDataModel = (ManorDataModel)dataModel; _fiefService.ManorList[index] = (ManorDataModel)tempDataModel.Clone(); } else if (dataModel.GetType() == typeof(BoatbuildingDataModel)) { BoatbuildingDataModel tempDataModel = (BoatbuildingDataModel)dataModel; _fiefService.BoatbuildingList[index] = (BoatbuildingDataModel)tempDataModel.Clone(); } else if (dataModel.GetType() == typeof(ExpensesDataModel)) { ExpensesDataModel tempDataModel = (ExpensesDataModel)dataModel; _fiefService.ExpensesList[index] = (ExpensesDataModel)tempDataModel.Clone(); } else if (dataModel.GetType() == typeof(StewardsDataModel)) { StewardsDataModel tempDataModel = (StewardsDataModel)dataModel; for (int x = 0; x < _fiefService.StewardsList.Count; x++) { _fiefService.StewardsList[x] = (StewardsDataModel)tempDataModel.Clone(); } } else if (dataModel.GetType() == typeof(SubsidiaryDataModel)) { SubsidiaryDataModel tempDataModel = (SubsidiaryDataModel)dataModel; _fiefService.SubsidiaryList[index] = (SubsidiaryDataModel)tempDataModel.Clone(); } else if (dataModel.GetType() == typeof(IncomeDataModel)) { IncomeDataModel tempDataModel = (IncomeDataModel)dataModel; _fiefService.IncomeList[index] = (IncomeDataModel)tempDataModel.Clone(); } else if (dataModel.GetType() == typeof(BuildingsDataModel)) { BuildingsDataModel tempDataModel = (BuildingsDataModel)dataModel; _fiefService.BuildingsList[index] = (BuildingsDataModel)tempDataModel.Clone(); } else if (dataModel.GetType() == typeof(WeatherDataModel)) { WeatherDataModel tempDataModel = (WeatherDataModel)dataModel; _fiefService.WeatherList[index] = (WeatherDataModel)tempDataModel.Clone(); } else if (dataModel.GetType() == typeof(MinesDataModel)) { MinesDataModel tempDataModel = (MinesDataModel)dataModel; _fiefService.MinesList[index] = (MinesDataModel)tempDataModel.Clone(); } else if (dataModel.GetType() == typeof(PortDataModel)) { PortDataModel tempDataModel = (PortDataModel)dataModel; _fiefService.PortsList[index] = (PortDataModel)tempDataModel.Clone(); } else if (dataModel.GetType() == typeof(TradeDataModel)) { TradeDataModel tempDataModel = (TradeDataModel)dataModel; _fiefService.TradeList[index] = (TradeDataModel)tempDataModel.Clone(); } else { Console.WriteLine("ERROR!"); } } }