示例#1
0
        public async Task <IActionResult> Create(GuestViewModel model)
        {
            var result = await _guestService.Create(model);

            if (result != default)
            {
                return(Created($"/api/event/{model.Id}", result));
            }
            return(BadRequest());
        }
示例#2
0
        public HttpResponseMessage Post(HttpRequestMessage request, [FromBody] GuestModel value)
        {
            ValidationResult guestValidation = guestValidator.Validate(value);

            if (guestValidation.IsValid)
            {
                GuestDTO newGuest = toDtoMapper.Map <GuestModel, GuestDTO>(value);
                guestService.Create(newGuest);
                return(request.CreateResponse(HttpStatusCode.NoContent));
            }

            return(request.CreateResponse(HttpStatusCode.BadRequest, guestValidation.Errors));
        }
示例#3
0
        public HttpResponseMessage Post(HttpRequestMessage request, [FromBody] GuestModel value)
        {
            try
            {
                var mapper = new MapperConfiguration(cfg => cfg.CreateMap <GuestModel, GuestDTO>()).CreateMapper();
                var data   = mapper.Map <GuestModel, GuestDTO>(value);

                service.Create(data);
                return(request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception exception)
            {
                return(request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
        public HttpResponseMessage AddGuest(int eventID, Guest guest)
        {
            var host = _userService.GetUserByWindowsName(User.Identity.Name).Data;

            if (host == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden));
            }

            guest.HostID = host.UserID;
            _guestService.Create(guest);
            var ev = _service.GetByID(eventID).Data;

            guest.Event = ev;
            guest.Host  = host;
            if (ev != null)
            {
                ev.GuestsInEvent.Add(guest);
                _service.Update(ev);
                _participantsContext.AddGuest(new EventGuestDTO(guest));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public ActionResult NewPerson(PersonEmailViewModel model, HttpPostedFileBase file)
        {
            if (!string.IsNullOrEmpty(model.UserName) || !string.IsNullOrEmpty(model.Email))
            {
                var person = _personService.GetAllForLogin().FirstOrDefault(x => x.Email.ToUpper() == model.Email.ToUpper());

                if (person != null)
                {
                    if (model.PersonID == 0)
                    {
                        ModelState.AddModelError("UserName", "This email address already exists, please use a different email address.");
                    }
                    else
                    {
                        if (model.PersonID != person.PersonID)
                        {
                            ModelState.AddModelError("UserName", "This email address already exists, please use a different email address.");
                        }
                    }
                }
            }

            if (ModelState.IsValid)
            {
                Mapper.CreateMap <PersonEmailViewModel, Person>();
                Person person = Mapper.Map <PersonEmailViewModel, Person>(model);

                if (model.PersonID == 0)
                {
                    person.HotelId      = HotelID;
                    person.DisplayName  = model.Email;
                    person.Email        = model.Email;
                    person.FirstName    = model.FirstName;
                    person.LastName     = model.Email;
                    person.Password     = model.Password;
                    person.Username     = model.Email;
                    person.PersonTypeId = (int)PersonTypeEnum.Guest;
                    person.IsActive     = true;
                    person.Address      = model.Email;

                    person.Title      = model.Email;
                    person.MiddleName = model.Email;
                    person.StartDate  = DateTime.Now;
                    person.EndDate    = DateTime.Now;

                    person.Guardian                  = model.Guardian;
                    person.GuardianAddress           = model.GuardianAddress;
                    person.PreviousEmployer          = model.PreviousEmployer;
                    person.ReasonForLeaving          = model.ReasonForLeaving;
                    person.Notes                     = model.Notes;
                    person.BirthDate                 = DateTime.Now;
                    person.PreviousEmployerStartDate = DateTime.Now;
                    person.PreviousEmployerEndDate   = DateTime.Now;
                    person.IdNumber                  = "123456789";
                    var extension = "";

                    if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                    {
                        extension = Path.GetExtension(Request.Files[0].FileName);
                        Stream imageStream = Request.Files[0].InputStream;
                        Image  img         = Image.FromStream(imageStream);
                        var    fileNewName = person.Email + extension;
                        var    path        = Path.Combine(Server.MapPath("~/Products"), fileNewName);
                        try
                        {
                            img.Save(path);
                            person.PicturePath = fileNewName;
                        }
                        catch
                        {
                        }
                    }

                    person.FullMember = true;

                    person = _personService.Create(person);

                    var guest = new Guest();
                    guest.FullName    = person.DisplayName;
                    guest.Address     = person.Address;
                    guest.Telephone   = person.Telephone;
                    guest.Mobile      = person.Mobile;
                    guest.CountryId   = 0;
                    guest.Status      = "LIVE";
                    guest.CarDetails  = "";
                    guest.Notes       = person.Notes;
                    guest.Email       = person.Email;
                    guest.IsActive    = true;
                    guest.CreatedDate = DateTime.Now;
                    guest.HotelId     = person.HotelId;
                    guest.PersonId    = person.PersonID;
                    guest.IsChild     = false;

                    if (model.PersonTypeId == (int)PersonTypeEnum.Child)
                    {
                        guest.IsChild = true;
                    }

                    guest             = _guestService.Create(guest);
                    person.IdNumber   = guest.Id.ToString();
                    person.FullMember = true;
                    _personService.Update(person);

                    ActivateGameAccount(person);
                }
                else
                {
                    var existingPerson = _personService.GetById(model.PersonID);

                    existingPerson.Email      = model.Email;
                    existingPerson.FirstName  = model.FirstName;
                    existingPerson.LastName   = model.LastName;
                    existingPerson.Password   = model.Password;
                    existingPerson.Username   = model.Email;
                    existingPerson.FullMember = true;

                    //existingPerson.PersonTypeId = model.PersonTypeId;
                    existingPerson.IsActive = true;
                    existingPerson.Address  = model.Address;

                    existingPerson.Title      = model.Title;
                    existingPerson.MiddleName = model.MiddleName;
                    existingPerson.StartDate  = DateTime.Now;
                    existingPerson.EndDate    = DateTime.Now;

                    existingPerson.Guardian         = model.Guardian;
                    existingPerson.GuardianAddress  = model.GuardianAddress;
                    existingPerson.PreviousEmployer = model.PreviousEmployer;
                    existingPerson.ReasonForLeaving = model.ReasonForLeaving;
                    existingPerson.Notes            = model.Notes;

                    if (string.IsNullOrEmpty(model.UserName))
                    {
                        model.UserName = model.Email;
                    }
                    //existingPerson.Username = model.Email;
                    existingPerson.Password = model.Password;
                    existingPerson.Email    = model.Email;
                    // existingPerson.PersonTypeId = model.PersonTypeId;

                    existingPerson.BirthDate = DateTime.Now;
                    existingPerson.PreviousEmployerStartDate = DateTime.Now;
                    existingPerson.PreviousEmployerEndDate   = DateTime.Now;
                    existingPerson.StartDate = DateTime.Now;
                    existingPerson.EndDate   = DateTime.Now;
                    existingPerson.BirthDate = model.BirthDate;

                    existingPerson.Telephone    = model.Telephone;
                    existingPerson.Mobile       = model.Mobile;
                    existingPerson.JobTitle     = model.JobTitle;
                    existingPerson.CityState    = model.CityState;
                    existingPerson.WorkAddress  = model.WorkAddress;
                    existingPerson.PlaceOfBirth = model.PlaceOfBirth;
                    existingPerson.Department   = model.Department;
                    //existingPerson.IdNumber = model.IdNumber;
                    existingPerson.BankDetails   = model.BankDetails;
                    existingPerson.AccountNumber = model.AccountNumber;
                    existingPerson.Salary        = model.Salary;
                    existingPerson.MaritalStatus = model.MaritalStatus;
                    existingPerson.NoOfChildren  = model.NoOfChildren;

                    if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                    {
                        var    extension   = Path.GetExtension(Request.Files[0].FileName);
                        Stream imageStream = Request.Files[0].InputStream;
                        Image  img         = Image.FromStream(imageStream);
                        var    fileNewName = person.FirstName + person.LastName + extension;
                        var    path        = Path.Combine(Server.MapPath("~/Products"), fileNewName);
                        try
                        {
                            img.Save(path);
                            existingPerson.PicturePath = fileNewName;
                        }
                        catch
                        {
                        }
                    }

                    _personService.Update(existingPerson);

                    var existingGuest = _guestService.GetAll(HotelID).FirstOrDefault(x => x.PersonId == existingPerson.PersonID);

                    if (existingGuest != null)
                    {
                        existingGuest.FullName    = existingPerson.FirstName + " " + existingPerson.LastName;
                        existingGuest.Address     = existingPerson.Address;
                        existingGuest.Telephone   = existingPerson.Telephone;
                        existingGuest.Mobile      = existingPerson.Mobile;
                        existingGuest.CountryId   = 0;
                        existingGuest.Status      = "LIVE";
                        existingGuest.CarDetails  = "";
                        existingGuest.Notes       = existingPerson.Notes;
                        existingGuest.Email       = existingPerson.Email;
                        existingGuest.IsActive    = true;
                        existingGuest.CreatedDate = DateTime.Now;
                        existingGuest.HotelId     = existingPerson.HotelId;
                        //existingGuest. = existingPerson.existingPersonID;
                        existingGuest.IsChild = false;

                        if (model.PersonTypeId == (int)PersonTypeEnum.Child)
                        {
                            existingGuest.IsChild = true;
                        }

                        _guestService.Update(existingGuest);
                    }
                }

                return(RedirectToAction("AdminLogin"));
            }

            return(View(model));
        }