Exemplo n.º 1
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] Entry entry)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != entry.Id)
            {
                return(BadRequest());
            }

            _context.Entry(entry).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EntryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <int> Put(PhoneBookEntry entity)
        {
            var phonebookentry = await _context.PhoneBookEntries.FindAsync(entity.Id);

            _context.Entry(phonebookentry).CurrentValues.SetValues(entity);
            return(1);
        }
Exemplo n.º 3
0
        public async Task <int> Put(DomainModels.PhoneBook entity)
        {
            var phonebook = await _context.PhoneBooks.FindAsync(entity.Id);

            _context.Entry(phonebook).CurrentValues.SetValues(entity);
            return(1);
        }
Exemplo n.º 4
0
 public ActionResult Edit(Phone phone, int?id)
 {
     if (ModelState.IsValid)
     {
         dbContext.Entry(phone).State = EntityState.Modified;
         dbContext.SaveChanges();
         return(RedirectToAction("Index", new { id = id }));
     }
     return(View(phone));
 }
 public ActionResult Edit(Person person)
 {
     if (ModelState.IsValid)
     {
         dbContext.Entry(person).State = EntityState.Modified;
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(person));
 }
 public ActionResult Edit([Bind(Include = "Id,UserName,Phone,Information,CreatedAt")] PhoneNumber phoneNumber)
 {
     if (ModelState.IsValid)
     {
         db.Entry(phoneNumber).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(phoneNumber));
 }
Exemplo n.º 7
0
        public async Task <Result <Employee> > Handle(UpdateEmployeeCommand request, CancellationToken cancellationToken)
        {
            var result = _validator.Validate(request, ruleSet: "PreValidationEmployeeUpdate");

            if (result.Errors.Count > 0)
            {
                return(Result.Failure <Employee>(result.Errors.First().ErrorMessage));
            }

            var employeeDb = _mapper.Map <EmployeeDb>(request);

            _context.Entry(employeeDb).State = EntityState.Modified;
            await _context.SaveChangesAsync(cancellationToken);

            return(Result.Ok <Employee>(_mapper.Map <Employee>(employeeDb)));
        }
Exemplo n.º 8
0
 public void UpdatePhoneContact(PhoneContact contact)
 {
     context.Entry(contact).State = EntityState.Modified;
 }
 private void SetCurrentValues(object oldEntity, object curEntity)
 {
     ctx.Entry(oldEntity).CurrentValues.SetValues(curEntity);
 }
Exemplo n.º 10
0
 public void Update(T entity)
 {
     _dbSet.Attach(entity);
     _dbContext.Entry(entity).State = EntityState.Modified;
 }
Exemplo n.º 11
0
 public void UpdateContact(Contact newContact)
 {
     _phoneBookDbContext.Entry(newContact).State = EntityState.Modified;
 }
Exemplo n.º 12
0
        public JsonResult Index()
        {
            List <ContactVM> contactVMs = new List <ContactVM>();
            var contacts = db.Contacts;

            foreach (var contact in contacts)
            {
                db.Entry(contact).Collection(x => x.PhoneNumber).Load();
                db.Entry(contact).Collection(x => x.Note).Load();
            }

            foreach (var item in contacts)
            {
                contactVMs.Add(MapperUtil.MapToContactVM(item));
            }

            return(Json(contactVMs, JsonRequestBehavior.AllowGet));
        }