Beispiel #1
0
        public async Task <IActionResult> Edit(CompanyEditBindingModel model)
        {
            if (ModelState.IsValid)
            {
                CompanyEditServiceModel serviceModel = new CompanyEditServiceModel()
                {
                    CompanyId    = model.CompanyId,
                    CreationDate = model.CreationDate,
                    Name         = model.Name
                };

                bool result = await this._companyServices.UpdateAsync(serviceModel);

                if (!result)
                {
                    return(RedirectToAction("Error", "Home"));
                }

                return(RedirectToAction("Details", new { id = model.CompanyId }));
            }

            return(View(model));
        }
Beispiel #2
0
        public async Task <bool> UpdateAsync(CompanyEditServiceModel model)
        {
            Company dbECompany = await this._context.Companies.FirstOrDefaultAsync(e => e.CompanyId == model.CompanyId);

            if (dbECompany == null)
            {
                return(false);
            }

            dbECompany.Name         = model.Name;
            dbECompany.CreationDate = model.CreationDate;

            var companyToUpdate = _context.Companies.Attach(dbECompany);

            companyToUpdate.State = EntityState.Modified;
            int result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                return(true);
            }

            return(false);
        }