public async Task<bool> UpdateCompany(int id, Company company) { using (db = new Diplomna_newEntities()) { Company companyFromDb = await db.Companies.FindAsync(id); companyFromDb.AddressText = company.AddressText; companyFromDb.CityID = company.CityID; companyFromDb.CompanyName = company.CompanyName; companyFromDb.Email = company.Email; companyFromDb.Phones = company.Phones; db.Entry(companyFromDb).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!(await CompanyExists(id))) { return false; // does not exist } else { throw; } } return true; } }
public async Task<Tuple<int, Company>> InsertCompany(Company company) { company.AddedOn = DateTime.Now; company.IsDeleted = false; company = await _companiesDal.InsertCompany(company); return new Tuple<int, Company>(company.CompanyID, company); }
public async Task<ResponseModel> UpdateCompany(int id, Company company) { ResponseModel result = new ResponseModel(); if (id != company.CompanyID) { result.Errors.Add(new Error() { ErrorType = Models.Enums.ErrorTypes.Validation, ShortMessage = "Номерата на компанията на са еднакви!" }); return result; } try { bool success = await _companiesDal.UpdateCompany(id, company); if (!success) { result.Errors.Add(new Error() { ErrorType = Models.Enums.ErrorTypes.NotFound, ShortMessage = "Фирмата не беше намерена!" }); return result; } result.Messages.Add("Данните за фирмата бяха обновени!"); } catch (Exception ex) { result.Errors.Add(new Error() { ErrorType = Models.Enums.ErrorTypes.Exception, ShortMessage = "Възникна проблем със запазването на данните!", LongMessage = ex.Message.ToString() }); return result; } return result; }
public async Task<Company> InsertCompany(Company company) { using (db = new Diplomna_newEntities()) { db.Companies.Add(company); await db.SaveChangesAsync(); return company; } }