Exemple #1
0
        public Task <bool> Handle(UpdateCitizenCommand message, CancellationToken cancellationToken)
        {
            var citizenActual = _citizenRepository.GetById(message.Id);

            if (!CitizenExistent(message.Id, message.MessageType))
            {
                return(Task.FromResult(false));
            }

            var citizen = new Citizen(message.Id, message.Name, message.NickName, message.Document, message.Email, message.Gender, citizenActual.DateRegister);

            if (!CitizenIsValid(citizen))
            {
                return(Task.FromResult(false));
            }

            _citizenRepository.Update(citizen);

            if (Commit())
            {
                _mediator.PublishEvent(new CitizenUpdatedEvent(citizen.Id, citizen.Name, citizen.NickName, citizen.Document, citizen.Email, citizen.Gender, citizen.DateRegister));
            }

            return(Task.FromResult(true));
        }
Exemple #2
0
        public ActionResult HandleChanges(StoreDataHandler handler)
        {
            List <Citizen> citizens     = handler.ObjectData <Citizen>();
            string         errorMessage = null;

            if (handler.Action == StoreAction.Create)
            {
                try
                {
                    foreach (Citizen created in citizens)
                    {
                        repo.Create(created);
                    }
                }catch (Exception e)
                {
                    errorMessage = e.Message;
                }
            }
            else if (handler.Action == StoreAction.Destroy)
            {
                foreach (Citizen deleted in citizens)
                {
                    repo.Delete(deleted.Id);
                    //citizen citizen = await db.citizens.FirstOrDefaultAsync(c => c.id == deleted.id);
                    //db.citizens.Remove(citizen);
                    //await db.SaveChangesAsync();
                }
            }
            else if (handler.Action == StoreAction.Update)
            {
                foreach (Citizen updated in citizens)
                {
                    try
                    {
                        repo.Update(updated);
                    }
                    catch (Exception e)
                    {
                        errorMessage = e.Message;
                    }
                    //citizen citizen = await db.citizens.FirstOrDefaultAsync(c => c.id == updated.id);
                    //CitizenHelper.CitizenUpdate(citizen, updated);
                    //await db.SaveChangesAsync();
                }
            }

            if (errorMessage != null)
            {
                return(this.Store(errorMessage));
            }

            return(handler.Action != StoreAction.Destroy ? (ActionResult)this.Store(citizens) : (ActionResult)this.Content(""));
        }
        public IActionResult UpdateCitizen(RegisterCitizen registerCitizen)
        {
            var logged_user_id      = signInManager.UserManager.GetUserId(User);
            var logged_user_citizen = userManager.Users
                                      .Where(usr => usr.Id == logged_user_id)
                                      .FirstOrDefault();

            var user = userManager.Users.Where(u => u.Id == logged_user_id).FirstOrDefault();

            user.Name        = registerCitizen.Name;
            user.BirthDate   = registerCitizen.BirthDate;
            user.Address     = registerCitizen.Address;
            user.City        = registerCitizen.City;
            user.State       = registerCitizen.State;
            user.Height      = registerCitizen.Height;
            user.Weight      = registerCitizen.Weight;
            user.Gender      = registerCitizen.Gender;
            user.CheckupData = registerCitizen.CheckupData;
            user.Bloodgroup  = registerCitizen.Bloodgroup;
            user.Mobile      = registerCitizen.Mobile;
            user.hid         = userManager.Users.Where(us => us.HospitalId == registerCitizen.Hospital_id_select).FirstOrDefault().Id;

            CitizenHospital ch = new CitizenHospital()
            {
                CitizenId = logged_user_citizen.CitizenId,
                Hospital  = userManager.Users.Where(us => us.HospitalId == registerCitizen.Hospital_id_select).FirstOrDefault(),
            };

            var ch_changes = context.CitizenHospitals.Attach(ch);

            ch_changes.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            context.SaveChanges();

            _citizenRepository.Update(user);
            TempData["SuccessMessage"] = "Profile Updated Successfully.";
            return(RedirectToAction("Dashboard", "Citizen"));
        }
Exemple #4
0
 public async Task <Citizen> DeleteCitizenAsync(Citizen citizen)
 {
     citizen.IsActive = false;
     return(await Task.FromResult(_citizenRepository.Update(citizen)));
 }
Exemple #5
0
 public async void Update(long id, Citizen citizen)
 {
     await _citizenRepository.Update(id, citizen);
 }