Exemplo n.º 1
0
        public IActionResult Update(int id, ContactUpdateViewModel contact)
        {
            Contact domainContact = new Contact()
            {
                Id            = id,
                Naam          = contact.Naam,
                Voornaam      = contact.Voornaam,
                Geslacht      = contact.Geslacht,
                GeboorteDatum = contact.GeboorteDatum,
                Email         = contact.Email,
                TelefoonNr    = contact.TelefoonNr,
                Adres         = contact.Adres,
                Beschrijving  = contact.Beschrijving,
                Category      = contact.Category
            };

            if (contact.Avatar != null)
            {
                var bytes = GetBytesFromFile(contact.Avatar);
                domainContact.Avatar = bytes;
            }
            else
            {
                domainContact.Avatar = contact.FileBytes;
            }

            _contactDatabase.Update(id, domainContact);

            return(RedirectToAction("Details", new { Id = id }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateContactPartial(ContactUpdateViewModel model, string command)
        {
            if (!Request.IsAjaxRequest())
            {
                return(RedirectToAction("BadRequest", "Home"));
            }

            if (model == null)
            {
                return(PartialView("_FailureToLoadDataPartial"));
            }

            ViewBag.HttpMethod = Request.Method;

            var contactEntity = _contactService.GetContact(model.Id).Data;

            if (contactEntity == null)
            {
                model.IsSuccess    = false;
                model.ErrorMessage = "Entry doesn't exist.";
                return(View(model));
            }

            if (command == "Delete")
            {
                ServiceResultModel = await _contactService.DeleteContactEntityAsync(model.Id);

                if (ServiceResultModel.IsSuccess)
                {
                    return(PartialView("_SuccessDeletePartial"));
                }
                else
                {
                    model.ErrorMessage = ServiceResultModel.ErrorMessage;
                }
            }

            if (command == "Update" && ModelState.IsValid)
            {
                contactEntity = model.UpdateBase(contactEntity);

                ServiceResultModel = await _contactService.UpdateContactEntityAsync(contactEntity);

                if (ServiceResultModel.IsSuccess)
                {
                    return(PartialView("_SuccessUpdatePartial"));
                }
                else
                {
                    model.ErrorMessage = ServiceResultModel.ErrorMessage;
                }
            }

            return(PartialView("_UpdateContactPartial", model));
        }
Exemplo n.º 3
0
        public IActionResult Update(int id)
        {
            Contact contactFromDb = _contactDabase.GetContact(id);
            ContactUpdateViewModel contactToUpdate = new ContactUpdateViewModel()
            {
                Voornaam      = contactFromDb.Voornaam,
                Naam          = contactFromDb.Naam,
                Geslacht      = contactFromDb.Geslacht,
                Geboortedatum = contactFromDb.Geboortedatum,
                TelefoonNr    = contactFromDb.TelefoonNr,
                Email         = contactFromDb.Email,
                Beschrijving  = contactFromDb.Beschrijving,
                Adres         = contactFromDb.Adres
            };

            return(View(contactToUpdate));
        }
Exemplo n.º 4
0
        public IActionResult Update(int id)
        {
            Contact contactFromDb          = _contactDatabase.GetContact(id);
            ContactUpdateViewModel contact = new ContactUpdateViewModel()
            {
                Naam          = contactFromDb.Naam,
                Voornaam      = contactFromDb.Voornaam,
                Geslacht      = contactFromDb.Geslacht,
                GeboorteDatum = contactFromDb.GeboorteDatum,
                Email         = contactFromDb.Email,
                TelefoonNr    = contactFromDb.TelefoonNr,
                Adres         = contactFromDb.Adres,
                Beschrijving  = contactFromDb.Beschrijving,
                FileBytes     = contactFromDb.Avatar,
                Category      = contactFromDb.Category
            };

            return(View(contact));
        }
        [ValidateAntiForgeryToken] //Prevents cross-site Request Forgery Attacks
        public async Task <IActionResult> Create(ContactUpdateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var contact = _mapper.Map <Contact>(model);
                //new Contact
                //{
                //    Id = model.Id,
                //    FirstName = model.FirstName,
                //    MiddleName = model.MiddleName,
                //    LastName = model.LastName
                //};

                await _contactService.CreateAsync(contact);

                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
Exemplo n.º 6
0
        public IActionResult UpdateContactPartial(int id)
        {
            if (!Request.IsAjaxRequest())
            {
                return(RedirectToAction("BadRequest", "Home"));
            }

            if (id == 0)
            {
                return(PartialView("_FailureToLoadDataPartial"));
            }

            var contactEntity = _contactService.GetContact(id).Data;

            if (contactEntity == null)
            {
                return(PartialView("_FailureToLoadDataPartial"));
            }

            var model = new ContactUpdateViewModel(contactEntity);

            return(PartialView("_UpdateContactPartial", model));
        }
Exemplo n.º 7
0
        public IActionResult Update(int id, ContactUpdateViewModel model)
        {
            if (!TryValidateModel(model))
            {
                return(View());
            }

            Contact contactToUpdate = new Contact()
            {
                Id            = id,
                Voornaam      = model.Voornaam,
                Naam          = model.Naam,
                Geslacht      = model.Geslacht,
                Geboortedatum = model.Geboortedatum,
                TelefoonNr    = model.TelefoonNr,
                Email         = model.Email,
                Beschrijving  = model.Beschrijving,
                Adres         = model.Adres
            };

            _contactDabase.Update(id, contactToUpdate);

            return(RedirectToAction("Detail", new { Id = id }));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Details(ContactUpdateViewModel contact)
        {
            if (contact == null)
            {
                return(BadRequest());
            }

            var contactFromDb = _repository.GetContactById(contact.Id);

            if (contactFromDb.IsNull())
            {
                return(NotFound());
            }

            contactFromDb.Address       = contact.Address;
            contactFromDb.Birthday      = contact.Birthday;
            contactFromDb.Employer      = contact.Employer;
            contactFromDb.Lastname      = contact.Lastname;
            contactFromDb.Firstname     = contact.Firstname;
            contactFromDb.Middlename    = contact.Middlename;
            contactFromDb.BusinessTitle = contact.BusinessTitle;
            contactFromDb.Tags          = contact.Tags;

            if (contact.Image is { Length : > 0 })