public async Task <Camper> UpdateCamper(int portalId, int camperId, CamperModel camper) { if (camper.IsMinor && (string.IsNullOrEmpty(camper.ParentFirstName) || string.IsNullOrEmpty(camper.ParentLastName))) { throw new Exception("This parent's information is required for this minor camper."); } Camper dbCamper = await GetCamperById(portalId, camperId); dbCamper.FirstName = camper.FirstName.Trim(); dbCamper.LastName = camper.LastName.Trim(); dbCamper.BirthDate = camper.BirthDate != null ? new DateTimeOffset(new DateTime(camper.BirthDate.Value.Year, camper.BirthDate.Value.Month, camper.BirthDate.Value.Day, 0, 0, 0)) : (DateTimeOffset?)null; dbCamper.ParentFirstName = camper.ParentFirstName?.Trim(); dbCamper.ParentLastName = camper.ParentLastName?.Trim(); dbCamper.Allergies = camper.Allergies?.Trim(); dbCamper.Medicine = camper.Medicine?.Trim(); dbCamper.StartingBalance = camper.StartingBalance; dbCamper.IsActive = camper.IsActive; dbCamper.UpdatedDate = DateTimeOffset.Now; dbCamper.CabinId = camper.CabinId; dbCamper.LoginUser = camper.LoginUser; dbCamper.CounselorId = camper.CounselorId; dbCamper.GroupId = camper.GroupId; await Context.SaveChangesAsync(); return(dbCamper); }
public async Task <Camper> CreateCamper(int portalId, CamperModel camper) { if (camper.IsMinor && (string.IsNullOrEmpty(camper.ParentFirstName) || string.IsNullOrEmpty(camper.ParentLastName))) { throw new Exception("This parent's information is required for this minor camper."); } Camper newCamper = new Camper { PortalId = portalId, FirstName = camper.FirstName.Trim(), LastName = camper.LastName.Trim(), BirthDate = camper.BirthDate != null ? new DateTimeOffset(new DateTime(camper.BirthDate.Value.Year, camper.BirthDate.Value.Month, camper.BirthDate.Value.Day, 0, 0, 0)) : (DateTimeOffset?)null, ParentFirstName = camper.ParentFirstName?.Trim(), ParentLastName = camper.ParentLastName?.Trim(), Allergies = camper.Allergies?.Trim(), Medicine = camper.Medicine?.Trim(), StartingBalance = camper.StartingBalance, CreatedBy = camper.CreatedBy, CreatedDate = DateTimeOffset.Now, UpdatedDate = DateTimeOffset.Now, IsActive = true, IsDeleted = false, LoginUser = camper.LoginUser, CabinId = camper.CabinId, CounselorId = camper.CounselorId, GroupId = camper.GroupId }; await Context.Campers.AddAsync(newCamper); await Context.SaveChangesAsync(); return(newCamper); }
public async Task <ActionResult <AdjustedCamper> > UpdateCamper(int portalId, int camperId, [FromBody] CamperModel camper) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await ValidateCustomFields(portalId, camper.CustomFields); } catch (Exception ex) { return(BadRequest(ex.Message)); } Camper updatedCamper = await _camperRepository.UpdateCamper(portalId, camperId, camper); RedeemedCoupon camperCoupon = await _redeemedCouponRepository.GetCamperCoupon(camperId); if (camper.CouponId != null && (camperCoupon == null || camper.CouponId != camperCoupon.CouponId)) { await _redeemedCouponRepository.RedeemCoupon(camper.CouponId.Value, camperId); } else if (camper.CouponId == null && camperCoupon != null) { await _redeemedCouponRepository.RemoveRedeemedCoupon(camperId); } await SaveCustomFields(camperId, camper.CustomFields); AdjustedCamper adjustedCamper = await AdjustCamper(updatedCamper); return(Ok(adjustedCamper)); }
public async Task <ActionResult <AdjustedCamper> > CreateCamper(int portalId, [FromBody] CamperModel camper) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await ValidateCustomFields(portalId, camper.CustomFields); } catch (Exception ex) { return(BadRequest(ex.Message)); } Camper newCamper = await _camperRepository.CreateCamper(portalId, camper); if (camper.CouponId != null) { await _redeemedCouponRepository.RedeemCoupon(camper.CouponId.Value, newCamper.Id); } await SaveCustomFields(newCamper.Id, camper.CustomFields); AdjustedCamper adjustedCamper = await AdjustCamper(newCamper); return(Ok(adjustedCamper)); }
public CamperModel GetSpecific(int Id) { Camper result = _unitOfWork.CamperAanbiedingRepository.FindAll(t => t.Id == Id && t.Camper.Leverancier.Status == 1).Select(t => t.Camper).FirstOrDefault(); return(CamperModel.Parse(result, "")); }