public T GetRow <T>(DbDataReader dataReader) { var len = dataReader.FieldCount; var row = GetRowInstance(len); if (resultType == ResultType.Array) { var array = (object[])row; for (var i = 0; i < len; i++) { var rawValue = dataReader.GetValue(i); var value = rawValue == DBNull.Value ? null : rawValue; array[i] = value; } return((T)(object)array); } else { for (var i = 0; i < len; i++) { var rawValue = dataReader.GetValue(i); var value = rawValue == DBNull.Value ? null : rawValue; var key = dataReader.GetName(i); try { GetMapper(row)(key, value); } catch (Exception ex) { throw new CouldNotSetPropertyException(key, ex); } } return((T)row); } }
public static string GetExecutionPath(IWebResource resource) { if (resource == null) { throw new ArgumentNullException(nameof(resource)); } var path = GetMapper(resource.GetType())(resource); var queryString = HttpContext.Current.Request.QueryString; if (queryString.AllKeys.Any()) { foreach (var key in queryString.AllKeys) { if (path.Contains(key + "=")) { continue; } if (!path.Contains("?")) { path += "?"; } else if (!path.EndsWith("&")) { path += "&"; } path += key + "=" + queryString[key]; } } return(path); }
protected override AdditionalBooking DoPostPutDto(Client currentClient, AdditionalBookingDTO dto, AdditionalBooking entity, string path, object param) { if (entity == null) { entity = new AdditionalBooking(); } else { if (dto.PriceTTC == null) { dto.PriceTTC = entity.PriceTTC; } } GetMapper.Map <AdditionalBookingDTO, AdditionalBooking>(dto, entity); if (path.StartsWith("AdditionalBookingDTO") && dto.Booking == null) { validationDictionnary.AddModelError("Booking", GenericError.CANNOT_BE_NULL_OR_EMPTY); } if (dto.Booking != null && dto.Booking.Id != 0) { entity.Booking = BookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Booking, currentClient, path); } if (dto.BillItemCategory != null) { entity.BillItemCategory = BillItemCategoryService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.BillItemCategory, currentClient, path); } if (dto.Tax != null) { entity.Tax = TaxService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Tax, currentClient, path); } return(entity); }
protected override HomeConfig DoPostPutDto(Client currentClient, HomeConfigDTO dto, HomeConfig entity, string path, object param) { if (entity == null) { entity = new HomeConfig(); } else { if (dto.EnableDinner == null) { dto.EnableDinner = entity.EnableDinner; } if (dto.HourFormat24 == null) { dto.HourFormat24 = entity.HourFormat24; } } GetMapper.Map(dto, entity); if (dto.BookingCanceledMailTemplate != null) { entity.BookingCanceledMailTemplate = DocumentService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.BookingCanceledMailTemplate, currentClient, path); } if (dto.DefaultMailConfig != null) { entity.DefaultMailConfig = MailConfigService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.DefaultMailConfig, currentClient, path); } return(entity); }
protected override FieldGroup DoPostPutDto(Client currentClient, FieldGroupDTO dto, FieldGroup entity, string path, object param) { if (entity == null) { entity = new FieldGroup(); } GetMapper.Map(dto, entity); if (dto.PeopleFields != null) { PeopleFieldRepository.DeleteRange(entity.PeopleFields.Where(d => !dto.PeopleFields.Any(x => x.Id == d.Id))); dto.PeopleFields.ForEach(peopleField => { if (entity.PeopleFields.Count != 0 && peopleField.Id != 0 && entity.PeopleFields.Find(p => p.Id == peopleField.Id) != null) { return; } PeopleField toAdd = PeopleFieldService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, peopleField, currentClient, path); if (toAdd != null) { entity.PeopleFields.Add(toAdd); } }); } return(entity); }
public virtual RoomBookingDTO Compute(Client currentClient, int id, object param) { repo = (IRoomBookingRepository)base.repo; List <PeopleBooking> listPeopleBooking = null; List <Period> listPeriod = null; repo.includes.Add("Booking"); repo.includes.Add("Room"); ProcessDTOPostPut(null, id, currentClient); ValidateOrig(); repo.includes.Add("PeopleCategory"); listPeopleBooking = repo.GetPeopleBookingFromRoomBooking(orig.Id, currentClient.Id).ToList(); listPeriod = repo.GetPeriods((DateTime)orig.Booking.DateArrival, (DateTime)orig.Booking.DateDeparture, currentClient.Id).ToList(); finalPriceHT = 0; finalPriceTTC = 0; if (listPeopleBooking.Count == 0) { ComputeUniqPrice(listPeriod, currentClient); } else { ComputePricePerPerson(listPeopleBooking, listPeriod, currentClient); } if (!validationDictionnary.IsValid) { throw new ManahostValidationException(validationDictionnary); } orig.PriceHT = finalPriceHT; orig.PriceTTC = finalPriceTTC; repo.Update(orig); repo.Save(); return(GetMapper.Map <RoomBooking, RoomBookingDTO>(orig)); }
protected override SupplementRoomBooking DoPostPutDto(Client currentClient, SupplementRoomBookingDTO dto, SupplementRoomBooking entity, string path, object param) { if (entity == null) { entity = new SupplementRoomBooking(); } else { if (dto.PriceHT == null) { dto.PriceHT = entity.PriceHT; } if (dto.PriceTTC == null) { dto.PriceTTC = entity.PriceTTC; } } GetMapper.Map(dto, entity); if (dto.RoomSupplement != null) { entity.RoomSupplement = RoomSupplementService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.RoomSupplement, currentClient, path); } if (dto.RoomBooking != null) { entity.RoomBooking = RoomBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.RoomBooking, currentClient, path); } return(entity); }
public virtual MailLogDTO SendMail(Domain.Entity.Client currentClient, MailModel entity, object param) { List <string> recipients = new List <string>(); List <Document> documents = new List <Document>(); MailLog mailLog; ValidateNull(entity); if (!validation.PreValidatePost(validationDictionnary, currentClient, entity, param, repo, recipients, documents)) { throw new ManahostValidationException(validationDictionnary); } IHomeRepository homeRepo = ((MailController.AdditionalRepositories)param).HomeRepo; MailConfig mailconfig = repo.GetMailConfigById(entity.MailConfigId, currentClient.Id); Mailling.SendMailBcc(new InfosMailling(mailconfig.Smtp, (int)mailconfig.SmtpPort, mailconfig.Email, homeRepo.GetHomeById(mailconfig.HomeId, currentClient.Id).Title, Encoding.UTF8.GetString(Convert.FromBase64String(entity.Password))) { body = entity.Body, prio = System.Net.Mail.MailPriority.Normal, subject = entity.Subject, toPeople = recipients, ssl = (bool)mailconfig.IsSSL, attachments = MailUtils.GetAttachments(documents, mailconfig.Home) }, mailLog = new MailLog() { DateSended = DateTime.UtcNow, To = String.Join(",", recipients.ToArray()), Successful = true, HomeId = mailconfig.HomeId }); repo.Add <MailLog>(mailLog); return(GetMapper.Map <MailLog, MailLogDTO>(mailLog)); }
protected override PricePerPerson DoPostPutDto(Client currentClient, PricePerPersonDTO dto, PricePerPerson entity, string path, object param) { if (entity == null) { entity = new PricePerPerson(); } GetMapper.Map(dto, entity); if (dto.PeopleCategory != null) { entity.PeopleCategory = PeopleCategoryService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.PeopleCategory, currentClient, path); } if (dto.Period != null) { entity.Period = PeriodService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Period, currentClient, path); } if (dto.Room != null) { entity.Room = RoomService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Room, currentClient, path); } if (dto.Tax != null) { entity.Tax = TaxService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Tax, currentClient, path); } return(entity); }
protected override BookingStepConfig DoPostPutDto(Client currentClient, BookingStepConfigDTO dto, BookingStepConfig entity, string path, object param) { if (entity == null) { entity = new BookingStepConfig(); } GetMapper.Map <BookingStepConfigDTO, BookingStepConfig>(dto, entity); if (dto.BookingSteps != null) { BookingStepRepository.DeleteRange(entity.BookingSteps.Where(d => !dto.BookingSteps.Any(x => x.Id == d.Id))); dto.BookingSteps.ForEach(bookingStep => { if (entity.BookingSteps.Count != 0 && bookingStep.Id != 0 && entity.BookingSteps.Find(p => p.Id == bookingStep.Id) != null) { return; } BookingStep toAdd = BookingStepService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, bookingStep, currentClient, path); if (toAdd != null) { entity.BookingSteps.Add(toAdd); } }); } return(entity); }
protected override MealBooking DoPostPutDto(Client currentClient, MealBookingDTO dto, MealBooking entity, string path, object param) { if (entity == null) { entity = new MealBooking(); } else { if (dto.NumberOfPeople == null) { dto.NumberOfPeople = entity.NumberOfPeople; } } GetMapper.Map(dto, entity); if (dto.Meal != null) { entity.Meal = MealService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Meal, currentClient, path); } if (dto.PeopleCategory != null) { entity.PeopleCategory = PeopleCategoryService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.PeopleCategory, currentClient, path); } if (dto.DinnerBooking != null) { entity.DinnerBooking = DinnerBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.DinnerBooking, currentClient, path); } return(entity); }
protected override Meal DoPostPutDto(Client currentClient, MealDTO dto, Meal entity, string path, object param) { if (entity == null) { entity = new Meal(); } else { if (dto.RefHide == null) { dto.RefHide = entity.RefHide; } } GetMapper.Map(dto, entity); if (dto.BillItemCategory != null) { entity.BillItemCategory = BillitemCategoryService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.BillItemCategory, currentClient, path); } if (dto.Documents != null) { DocumentRepository.DeleteRange(entity.Documents.Where(d => !dto.Documents.Any(x => x.Id == d.Id))); dto.Documents.ForEach(document => { if (entity.Documents.Count != 0 && document.Id != 0 && entity.Documents.Find(p => p.Id == document.Id) != null) { return; } Document toAdd = DocumentService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, document, currentClient, path); if (toAdd != null) { entity.Documents.Add(toAdd); } }); } if (dto.MealCategory != null) { entity.MealCategory = MealCategoryService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.MealCategory, currentClient, path); } if (dto.MealPrices != null) { MealPrice.DeleteRange(entity.MealPrices.Where(d => !dto.MealPrices.Any(x => x.Id == d.Id))); dto.MealPrices.ForEach(mealPrice => { if (entity.MealPrices.Count != 0 && mealPrice.Id != 0 && entity.MealPrices.Find(p => p.Id == mealPrice.Id) != null) { return; } MealPrice toAdd = MealPriceService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, mealPrice, currentClient, path); if (toAdd != null) { entity.MealPrices.Add(toAdd); } }); } return(entity); }
protected override Room DoPostPutDto(Client currentClient, RoomDTO dto, Room entity, string path, object param) { if (entity == null) { entity = new Room(); } else { if (dto.RefHide == null) { dto.RefHide = entity.RefHide; } if (dto.Color == null) { dto.Color = entity.Color; } } GetMapper.Map <RoomDTO, Room>(dto, entity); if (dto.BillItemCategory != null) { entity.BillItemCategory = BillItemCategoryService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.BillItemCategory, currentClient, path); } if (dto.RoomCategory != null) { entity.RoomCategory = RoomCategoryService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.RoomCategory, currentClient, path); } if (dto.Beds != null) { BedRepository.DeleteRange(entity.Beds.Where(d => !dto.Beds.Any(x => x.Id == d.Id))); dto.Beds.ForEach(bed => { if (entity.Beds.Count != 0 && bed.Id != 0 && entity.Beds.Find(p => p.Id == bed.Id) != null) { return; } Bed toAdd = BedService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, bed, currentClient, path); if (toAdd != null) { entity.Beds.Add(toAdd); } }); } if (dto.Documents != null) { DocumentRepository.DeleteRange(entity.Documents.Where(d => !dto.Documents.Any(x => x.Id == d.Id))); dto.Documents.ForEach(document => { Document toAdd = DocumentService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, document, currentClient, path); if (toAdd != null) { entity.Documents.Add(toAdd); } }); } return(entity); }
public ActionResult Post(CreateProductVM model) { Product product = GetMapper.Map <Product>(model); _context.Products.Add(product); _context.SaveChanges(); return(Ok()); }
protected override People DoPostPutDto(Client currentClient, PeopleDTO dto, People entity, string path, object param) { if (entity == null) { entity = new People(); } GetMapper.Map <PeopleDTO, People>(dto, entity); return(entity); }
protected override GroupBillItem DoPostPutDto(Client currentClient, GroupBillItemDTO dto, GroupBillItem entity, string path, object param) { if (entity == null) { entity = new GroupBillItem(); } GetMapper.Map(dto, entity); return(entity); }
protected override Period DoPostPutDto(Client currentClient, PeriodDTO dto, Period entity, string path, object param) { if (entity == null) { entity = new Period(); } GetMapper.Map(dto, entity); return(entity); }
protected override DocumentCategory DoPostPutDto(Client currentClient, DocumentCategoryDTO dto, DocumentCategory entity, string path, object param) { if (entity == null) { entity = new DocumentCategory(); } GetMapper.Map(dto, entity); return(entity); }
protected override Home DoPostPutDto(Client currentClient, HomeDTO dto, Home entity, string path, object param) { if (entity == null) { entity = new Home(); } GetMapper.Map(dto, entity); return(entity); }
protected override BookingStep DoPostPutDto(Client currentClient, BookingStepDTO dto, BookingStep entity, string path, object param) { if (entity == null) { entity = new BookingStep(); } GetMapper.Map(dto, entity); if (path.StartsWith("BookingStepDTO") && dto.BookingStepConfig == null) { validationDictionnary.AddModelError("Booking", GenericError.CANNOT_BE_NULL_OR_EMPTY); throw new ManahostValidationException(validationDictionnary); } if (dto.BookingStepConfig != null) { entity.BookingStepConfig = BookingStepConfigService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.BookingStepConfig, currentClient, path); } if (dto.BookingStepIdNext != null && dto.BookingStepIdNext != 0) { entity.BookingStepNext = PreProcessDTOPostPut(dto.HomeId, new BookingStepDTO() { Id = (int)dto.BookingStepIdNext }, currentClient, path, param); } if (dto.BookingStepIdPrevious != null && dto.BookingStepIdPrevious != 0) { entity.BookingStepPrevious = PreProcessDTOPostPut(dto.HomeId, new BookingStepDTO() { Id = (int)dto.BookingStepIdPrevious }, currentClient, path, param); } if (dto.MailTemplate != null) { entity.MailTemplate = DocumentService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.MailTemplate, currentClient, path); } if (dto.Documents != null) { DocumentRepository.DeleteRange(entity.Documents.Where(d => !dto.Documents.Any(x => x.Id == d.Id))); dto.Documents.ForEach(document => { if (entity.Documents.Count != 0 && document.Id != 0 && entity.Documents.Find(p => p.Id == document.Id) != null) { return; } Document toAdd = DocumentService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, document, currentClient, path); if (toAdd != null) { entity.Documents.Add(toAdd); } }); } UpdateBookingStepPreviousOnPost(entity); return(entity); }
public ActionResult Coba1() { var siswa2 = new Siswa2() { Name = "Joko", Age = 24 }; Siswa1 siswa1 = GetMapper.Map <Siswa1>(siswa2); return(Ok()); }
public override HomeDTO DoGet(Client current, int homeId, object param) { Home home = repo.GetHomeById(homeId, current.Id); if (home == null) { validationDictionnary.AddModelError(TypeOfName.GetNameFromType <Home>(), GenericError.FORBIDDEN_RESOURCE_OR_DOES_NO_EXIST); throw new ManahostValidationException(validationDictionnary); } return(GetMapper.Map <Home, HomeDTO>(home)); }
public override IEnumerable <HomeDTO> DoGet(Client current, object param) { IEnumerable <Home> homes = repo.GetHomesForClient(current.Id); List <HomeDTO> lhomes = new List <HomeDTO>(); foreach (Home cur in homes) { lhomes.Add(GetMapper.Map <Home, HomeDTO>(cur)); } return(lhomes); }
public HomeDTO DoGetDefaultHome(Client currentClient) { Home home = repo.GetUniq(x => x.ClientId == currentClient.Id && x.isDefault == true); if (home == null) { validationDictionnary.AddModelError(TypeOfName.GetNameFromType <Home>(), GenericError.FORBIDDEN_RESOURCE_OR_DOES_NO_EXIST); throw new ManahostValidationException(validationDictionnary); } return(GetMapper.Map <Home, HomeDTO>(home)); }
public virtual ProductBookingDTO Compute(Client currentClient, int id, object param) { repo.includes.Add("Product"); repo.includes.Add("Product.Tax"); ProcessDTOPostPut(null, id, currentClient); ValidateOrig(); ComputePriceAndDuration(orig); repo.Update(orig); repo.Save(); return(GetMapper.Map <ProductBooking, ProductBookingDTO>(orig)); }
public virtual AdditionalBookingDTO Compute(Client currentClient, int id, object param) { repo.includes.Add("Tax"); ProcessDTOPostPut(null, id, currentClient); ValidateOrig(); orig.SetDateModification(DateTime.UtcNow); ComputeTaxPrice(orig); repo.Update(orig); repo.Save(); return(GetMapper.Map <AdditionalBooking, AdditionalBookingDTO>(orig)); }
protected override Supplier DoPostPutDto(Client currentClient, SupplierDTO dto, Supplier entity, string path, object param) { if (entity == null) entity = new Supplier(); else { dto.DateCreation = entity.DateCreation; } GetMapper.Map(dto, entity); return entity; }
public ActionResult Coba2() { var siswa3 = new Siswa3() { Name = "Joko", Age = 24, Alamat = "Malang" }; Siswa1 siswa1 = GetMapper.Map <Siswa1>(siswa3); return(Ok()); }
protected override Bill DoPostPutDto(Client currentClient, BillDTO dto, Bill entity, string path, object param) { if (entity == null) { entity = new Bill(); } GetMapper.Map(dto, entity); if (dto.Booking != null && dto.Booking.Id != 0) { entity.Booking = BookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Booking, currentClient, path); } if (dto.BillItems != null) { BillItemRepository.DeleteRange(entity.BillItems.Where(d => !dto.BillItems.Any(x => x.Id == d.Id))); dto.BillItems.ForEach(bitem => { if (entity.BillItems.Count != 0 && bitem.Id != 0 && entity.BillItems.Find(p => p.Id == bitem.Id) != null) { return; } BillItem toAdd = BillItemService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, bitem, currentClient, path); if (toAdd != null) { entity.BillItems.Add(toAdd); } }); } if (dto.PaymentMethods != null) { PaymentMethodRepository.DeleteRange(entity.PaymentMethods.Where(d => !dto.PaymentMethods.Any(x => x.Id == d.Id))); dto.PaymentMethods.ForEach(pm => { if (entity.PaymentMethods.Count != 0 && pm.Id != 0 && entity.PaymentMethods.Find(p => p.Id == pm.Id) != null) { return; } PaymentMethod toAdd = PaymentMethodService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, pm, currentClient, path); if (toAdd != null) { entity.PaymentMethods.Add(toAdd); } }); } if (dto.Supplier != null) { entity.Supplier = SupplierService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Supplier, currentClient, path); } return(entity); }
public virtual SupplementRoomBookingDTO Compute(Client currentClient, int id, object param) { repo.includes.Add("RoomSupplement.Tax"); ProcessDTOPostPut(null, id, currentClient); ValidateOrig(); orig.PriceHT = orig.RoomSupplement.PriceHT; orig.PriceTTC = orig.PriceHT; ComputeTaxPrice(orig.RoomSupplement); repo.Update(orig); repo.Save(); return(GetMapper.Map <SupplementRoomBooking, SupplementRoomBookingDTO>(orig)); }