public async Task <object> AddUpdateCompany(CompanyViewModel companyViewModel, string UserName) { if (companyViewModel.Id == 0) { MyMenu.Shared.Models.Company company = new MyMenu.Shared.Models.Company(); company.Name = companyViewModel.Name; company.Description = companyViewModel.Description; company.ImgUrl = companyViewModel.Photo; company.CreatedBy = UserName; company.CreatedAt = DateTime.Now; company.UpdatedBy = UserName; company.UpdatedAt = DateTime.Now; company.IsActive = true; company.IsDelete = false; await context.Company.AddAsync(company); await context.SaveChangesAsync(); return(company); } else { var company = await context.Company.FindAsync(companyViewModel.Id); company.Name = companyViewModel.Name; company.Description = companyViewModel.Description; company.UpdatedAt = DateTime.Now; company.UpdatedBy = UserName; company.IsActive = companyViewModel.IsActive; context.Company.Update(company); await context.SaveChangesAsync(); return(company); } }
public async Task <Shared.Models.Company> AddCompany(CompanyDetailViewModel newcompany, string userid) { var result = await context.User.FirstOrDefaultAsync(e => e.UserId == int.Parse(userid)); string fullname = result.FirstName + " " + result.LastName; MyMenu.Shared.Models.Company company = new MyMenu.Shared.Models.Company(); company.Name = newcompany.Name; company.Description = newcompany.Description; company.ImgUrl = newcompany.Photo; company.UserId = newcompany.UserId; company.CreatedBy = fullname; company.CreatedAt = DateTime.Now; company.UpdatedBy = fullname; company.UpdatedAt = DateTime.Now; company.IsActive = true; company.IsDelete = false; await context.Company.AddAsync(company); await context.SaveChangesAsync(); return(company); }