public BussinessDataModel CreateBusiness(BussinessDataModel businessDataModel) { if (businessDataModel != null) { BusinessDTO businessDTO = new BusinessDTO(); AddressDTO addressDTO = new AddressDTO(); PhoneDTO phoneDTO = new PhoneDTO(); EmailDTO emailDTO = new EmailDTO(); businessDTO = BussinessDataModelAssembler.ToBusinessDTO(businessDataModel); phoneDTO = BussinessDataModelAssembler.ToPhoneDTO(businessDataModel); emailDTO = BussinessDataModelAssembler.ToEmailDTO(businessDataModel); addressDTO = BussinessDataModelAssembler.ToAddressDTO(businessDataModel); if (businessDTO != null) { businessDTO = businessBL.Create(businessDTO); } if (phoneDTO != null) { phoneDTO = phonesBL.Create(phoneDTO); } if (emailDTO != null) { emailsBL.Create(emailDTO); } if (addressDTO != null) { addressBL.Create(addressDTO); } } return(businessDataModel); }
public BusinessDataModel Get(BusinessDTO modelDTO) { BusinessDataModel BusinessDataModel = null; if (modelDTO != null) { //List<BusinessAddressDTO> BusinessAddressDTO = (modelDTO.BusinessAddresses != null) ? modelDTO.BusinessAddresses.Select(p => p) : null; //AddressDTO oPrimaryAddressDTO = (BusinessAddressDTO != null) ? BusinessAddressDTO.Addres : null; List <AddressDTO> oPrimaryAddressDTO = (modelDTO.BusinessAddresses != null) ? modelDTO.BusinessAddresses.Where(p => p.BusinessID == modelDTO.BusinessID).Select(p => p.Addres).ToList() : null; List <ServiceDTO> servicesList = (modelDTO.Services != null) ? modelDTO.Services.Where(p => p.BusinessID == modelDTO.BusinessID).ToList() : null; List <AchievementDTO> oPrimaryAchievementDTO = (modelDTO.Achievements != null) ? modelDTO.Achievements.Where(p => p.BusinessID == modelDTO.BusinessID).Select(p => p).ToList() : null; BusinessPhoneDTO BusinessPhoneDTO = (modelDTO.BusinessPhones != null) ? modelDTO.BusinessPhones.Where(o => o.IsPrimary).FirstOrDefault() : null; PhoneDTO oPrimaryPhoneDTO = (BusinessPhoneDTO != null) ? BusinessPhoneDTO.Phone : null; //BusinessImageDTO BusinessImageDTO = (modelDTO.BusinessImages != null) ? modelDTO.BusinessImages.Where(o => o.IsPrimary).FirstOrDefault() : null; //ImageDTO oPrimaryImageDTO = (BusinessImageDTO != null) ? BusinessImageDTO.Image : null; ImageDTO oPrimaryImageDTO = (modelDTO.BusinessImages != null) ? modelDTO.BusinessImages.Where(o => o.IsPrimary).Select(p => p.Image).FirstOrDefault() : null; BusinessEmailDTO BusinessEmailDTO = (modelDTO.BusinessEmails != null) ? modelDTO.BusinessEmails.Where(o => o.IsPrimary).FirstOrDefault() : null; EmailDTO oPrimaryEmailDTO = (BusinessEmailDTO != null) ? BusinessEmailDTO.Email : null; BusinessDataModel = BusinessDataModelAssembler.ToDataModel(modelDTO, oPrimaryAddressDTO, oPrimaryPhoneDTO, oPrimaryEmailDTO, oPrimaryImageDTO, oPrimaryAchievementDTO, null, servicesList); BusinessDataModel.PrimaryAddressID = (modelDTO.BusinessAddresses != null) ? modelDTO.BusinessAddresses.FirstOrDefault(p => p.IsPrimary == true).AddressID : 0; //BusinessDataModel.BusinessAddressID = (BusinessAddressDTO != null) ? BusinessAddressDTO.BusinessAddressID : 0; BusinessDataModel.BusinessPhoneID = (BusinessPhoneDTO != null) ? BusinessPhoneDTO.BusinessPhoneID : 0; BusinessDataModel.BusinessEmailID = (BusinessEmailDTO != null) ? BusinessEmailDTO.BusinessEmailID : 0; } return(BusinessDataModel); }
public void UpdatePhoneCustomer(PhoneViewModel phoneVM) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <PhoneViewModel, PhoneDTO>()).CreateMapper(); PhoneDTO phoneDto = mapper.Map <PhoneViewModel, PhoneDTO>(phoneVM); service.UpdatePhone(phoneDto); }
public static ProfileDTO ProfileToProfileDTO(Profile profile, List <AddressType> addressTypes, List <PhoneType> phoneTypes) { ProfileDTO objProfileDTO = new ProfileDTO(); objProfileDTO.ProfileId = profile.ProfileId; objProfileDTO.FirstName = profile.FirstName; objProfileDTO.LastName = profile.LastName; objProfileDTO.Email = profile.Email; objProfileDTO.AddressDTO = new List <AddressDTO>(); objProfileDTO.PhoneDTO = new List <PhoneDTO>(); foreach (var profileAddress in profile.ProfileAddresses) { AddressDTO objAddressDTO = AddressToAddressDTO(profileAddress.Address); objAddressDTO.AddressTypeId = profileAddress.AddressTypeId; objProfileDTO.AddressDTO.Add(objAddressDTO); } foreach (var profilePhone in profile.ProfilePhones) { PhoneDTO objPhoneDTO = PhoneToPhoneDTO(profilePhone.Phone); objPhoneDTO.PhoneTypeId = profilePhone.PhoneTypeId; objProfileDTO.PhoneDTO.Add(objPhoneDTO); } return(objProfileDTO); }
/// <summary> /// Invoked when <see cref="ToDTO"/> operation is about to return. /// </summary> /// <param name="dto"><see cref="PhoneDTO"/> converted from <see cref="Phone"/>.</param> static partial void OnDTO(this Phone entity, PhoneDTO dto) { if (entity != null && entity.TypeCode != null) { dto.TypeCode = TypeCodeAssembler.ToDTO(entity.TypeCode); } }
public ActionResult CreateImage(IFormFile fileImage) { if (fileImage != null) { // путь к папке Files string path = "/images/" + fileImage.FileName; // сохраняем файл в папку Files в каталоге wwwroot using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create)) { fileImage.CopyTo(fileStream); } PhoneDTO phoneDto = service.GetPhone(1); //var mapper = new MapperConfiguration(cfg => cfg.CreateMap<PhoneDTO, // Phone>()).CreateMapper(); //Phone phone = mapper.Map<PhoneDTO, Phone>(phoneDto); ImageViewModel imageVM = new ImageViewModel { Name = fileImage.FileName, Path = path, ProductId = phoneDto.Id }; var mapper1 = new MapperConfiguration(cfg => cfg.CreateMap <ImageViewModel, ImageDTO>()).CreateMapper(); ImageDTO imageDto = mapper1.Map <ImageViewModel, ImageDTO>(imageVM); service.CreateImage(imageDto); } return(View()); }
public IHttpActionResult GetPhonesByTraderId(string traderId) { try { List <PhoneDTO> dtoList = new List <PhoneDTO>(); foreach (Phone phone in db.Phones) { if (phone.traderId == traderId) { PhoneDTO phdto = new PhoneDTO(); phdto.id = phone.id; phdto.number = phone.number; phdto.cityCode = phone.cityCode; phdto.countryCode = phone.countryCode; phdto.preferredFlag = phone.preferredFlag; phdto.phoneTypeId = phone.phoneTypeId; phdto.phoneType = db.PhoneTypes.First(pt => pt.phoneTypeId == phone.phoneTypeId).phoneType; phdto.traderId = phone.traderId; dtoList.Add(phdto); } } return(Ok <List <PhoneDTO> >(dtoList)); } catch (Exception exc) { string mess = exc.Message; ModelState.AddModelError("Message", "An unexpected error has occured during getting phones by trader id!"); return(BadRequest(ModelState)); } }
public IHttpActionResult GetPreferredPhone(string traderId, string preferredFlag) { try { var phn = db.Phones.FirstOrDefault(sn => sn.traderId == traderId && sn.preferredFlag == preferredFlag); if (phn != null) { PhoneDTO phdto = new PhoneDTO(); phdto.id = phn.id; phdto.number = phn.number; phdto.cityCode = phn.cityCode; phdto.countryCode = phn.countryCode; phdto.preferredFlag = phn.preferredFlag; phdto.phoneTypeId = phn.phoneTypeId; phdto.phoneType = db.PhoneTypes.First(ph => ph.phoneTypeId == ph.phoneTypeId).phoneType; phdto.traderId = phn.traderId; return(Ok <PhoneDTO>(phdto)); } return(Ok <Phone>(new Phone())); } catch (Exception exc) { string mess = exc.Message; ModelState.AddModelError("Message", "An unexpected error has occured during getting preferred phone by trader id!"); return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> PostPhone([FromBody] Phone phone) { if (!ModelState.IsValid) { ModelState.AddModelError("Message", "The phone details are not valid!"); return(BadRequest(ModelState)); } db.Phones.Add(phone); await db.SaveChangesAsync(); Phone lastPhone = await db.Phones.OrderByDescending(u => u.id).FirstAsync(); PhoneDTO adddto = new PhoneDTO(); adddto.id = lastPhone.id; adddto.number = lastPhone.number; adddto.cityCode = lastPhone.cityCode; adddto.countryCode = lastPhone.countryCode; adddto.preferredFlag = lastPhone.preferredFlag; adddto.phoneTypeId = lastPhone.phoneTypeId; adddto.phoneType = db.PhoneTypes.First(adt => adt.phoneTypeId == lastPhone.phoneTypeId).phoneType; adddto.traderId = lastPhone.traderId; return(Ok <PhoneDTO>(adddto)); }
public async Task <IHttpActionResult> GetPhone(int id) { Phone phone = await db.Phones.FindAsync(id); if (phone == null) { ModelState.AddModelError("Message", "Phone not found!"); return(BadRequest(ModelState)); } try { PhoneDTO phdto = new PhoneDTO(); phdto.id = phone.id; phdto.number = phone.number; phdto.cityCode = phone.cityCode; phdto.countryCode = phone.countryCode; phdto.preferredFlag = phone.preferredFlag; phdto.phoneTypeId = phone.phoneTypeId; phdto.phoneType = db.PhoneTypes.First(pt => pt.phoneTypeId == phone.phoneTypeId).phoneType; phdto.traderId = phone.traderId; return(Ok(phdto)); } catch (Exception exc) { string mess = exc.Message; ModelState.AddModelError("Message", "An unexpected error has occured during getting the phone by phone Id!"); return(BadRequest(ModelState)); } }
public void AddPhone(PhoneDTO phone) { Repository <Phone> repository = new Repository <Phone>(context); Phone p = Mapper.PhoneFromDTO(phone); repository.Create(p); }
public BusinessDataModel Update(BusinessDataModel dataModel) { if (dataModel != null) { BusinessDTO businessDTO = new BusinessDTO(); List <AddressDTO> addressDTO = new List <AddressDTO>(); PhoneDTO phoneDTO = new PhoneDTO(); EmailDTO emailDTO = new EmailDTO(); BusinessUserMapDTO businessUserMapDTO = new BusinessUserMapDTO(); businessDTO = BusinessDataModelAssembler.ToBusinessDTO(dataModel); phoneDTO = BusinessDataModelAssembler.ToPhoneDTO(dataModel); emailDTO = BusinessDataModelAssembler.ToEmailDTO(dataModel); addressDTO = BusinessDataModelAssembler.ToAddressDTO(dataModel); businessUserMapDTO = BusinessDataModelAssembler.ToBusinessUserMapDTO(dataModel); if (businessDTO != null) { businessDTO = businessBL.Update(businessDTO); } dataModel = BusinessDataModelAssembler.ToDataModel(businessDTO, addressDTO, phoneDTO, emailDTO, null, null, businessUserMapDTO, null); if (phoneDTO != null) { phoneDTO = phonesBL.Update(phoneDTO); } new BusinessPhoneBL().Update(new BusinessPhoneDTO() { BusinessID = dataModel.BusinessID, BusinessPhoneID = dataModel.BusinessPhoneID, IsPrimary = true }); dataModel = BusinessDataModelAssembler.ToDataModel(businessDTO, addressDTO, phoneDTO, emailDTO, null, null, businessUserMapDTO, null); if (emailDTO != null) { emailDTO = emailsBL.Update(emailDTO); } new BusinessEmailBL().Update(new BusinessEmailDTO() { BusinessID = dataModel.BusinessID, BusinessEmailID = dataModel.BusinessEmailID, IsPrimary = true }); dataModel = BusinessDataModelAssembler.ToDataModel(businessDTO, addressDTO, phoneDTO, emailDTO, null, null, businessUserMapDTO, null); if (addressDTO != null) { addressDTO = addressDTO.Select(p => addressBL.Update(p)).ToList(); } dataModel = BusinessDataModelAssembler.ToDataModel(businessDTO, addressDTO, phoneDTO, emailDTO, null, null, businessUserMapDTO, null); new BusinessAddressBL().Update(new BusinessAddressDTO() { BusinessID = dataModel.BusinessID, BusinessAddressID = dataModel.BusinessAddressID, IsPrimary = true }); } return(dataModel); }
public async Task <IHttpActionResult> PostPhone(Phone phone) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Phones.Add(phone); await db.SaveChangesAsync(); var dto = new PhoneDTO() { PhoneId = phone.PhoneId, Number = phone.Number, ContactsId = phone.Contacts_ContactsId, Info = phone.Info, Persons = phone.Persons.Select(ct => new SimplePersonIdDTO() { PersonId = ct.PersonId, FirstName = ct.Name, MiddleName = ct.MiddleName, LastName = ct.SurName, Email = ct.Email, AddressID = ct.Addressid, }) }; return(CreatedAtRoute("DefaultApi", new { id = phone.PhoneId }, dto)); }
public PhoneDTO Put(PhoneDTO phoneBook) { var phone = _mapper.Map <Phone>(phoneBook); var updatedUser = _repository.UpdateNumber(phone); return(_mapper.Map <PhoneDTO>(updatedUser)); }
public PhoneDTO Post(PhoneDTO phoneBook) { var phone = _mapper.Map <Phone>(phoneBook); _repository.AddNumber(phone); return(_mapper.Map <PhoneDTO>(phone)); }
public ActionResult UpdatePhoneCust(PhoneViewModel phoneVM) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <PhoneViewModel, PhoneDTO>()).CreateMapper(); PhoneDTO phoneDto = mapper.Map <PhoneViewModel, PhoneDTO>(phoneVM); service.UpdatePhone(phoneDto); return(View("Index")); }
public ActionResult <PhoneDTO> Put(int id, [FromBody] PhoneDTO phoneBook) { if (id != phoneBook.Id) { return(new BadRequestObjectResult("Id-s do not match!!!")); } return(_service.Put(phoneBook)); }
public PhoneDTO Create(PhoneDTO oPhoneDTO) { if (oPhoneDTO != null) { return(PhoneAssembler.ToDTO(oPhoneRepo.CreatePhone(PhoneAssembler.ToEntity(oPhoneDTO)))); } return(null); }
public static PhoneUI PhoneFromDTO(PhoneDTO phonedto) { PhoneUI result = new PhoneUI(); result.Mark = phonedto.Mark; result.Model = phonedto.Model; result.Price = phonedto.Price; result.ID = phonedto.ID; return(result); }
public static PhoneDTO PhoneFromUI(PhoneUI phoneui) { PhoneDTO result = new PhoneDTO(); result.Mark = phoneui.Mark; result.Model = phoneui.Model; result.Price = phoneui.Price; result.ID = phoneui.ID; return(result); }
public static PhoneDTO MapToDTO(PhoneDAO phone) { var p = new PhoneDTO(); p.Id = phone.Id; p.Number = phone.Number; p.Active = phone.Active; return(p); }
public async Task <HttpResponseMessage> insertPhoneAsync([Bind(Include = "Number")] PhoneDTO phone) { client = new HttpClient(); client.BaseAddress = new Uri(@"http://ec2-52-23-205-25.compute-1.amazonaws.com/pizzastoreapi/api/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = (await client.PostAsJsonAsync("phone", phone).ConfigureAwait(continueOnCapturedContext: false)); return(response); }
/// <summary> /// Update profile phone /// </summary> /// <param name="lstUpdatedPhoneDTO"></param> /// <param name="lstCurrentPhone"></param> /// <param name="profile"></param> private void UpdatePhone(List <PhoneDTO> lstUpdatedPhoneDTO, List <ProfilePhone> lstCurrentPhone, Profile profile) { if (lstUpdatedPhoneDTO == null && lstCurrentPhone == null) { return; } // if user has deleted all existing phones if (lstUpdatedPhoneDTO == null && lstCurrentPhone != null) { foreach (ProfilePhone profilePhone in lstCurrentPhone) { DeleteProfilePhone(profilePhone); } return; } // if user has added new phone and there was not any existing phone if (lstUpdatedPhoneDTO != null && lstCurrentPhone == null) { foreach (PhoneDTO phoneDTO in lstUpdatedPhoneDTO) { SavePhone(phoneDTO, profile); } return; } // if user has updated or deleted any record List <PhoneDTO> lstNewPhone = lstUpdatedPhoneDTO; // check if phone exists in database foreach (ProfilePhone profilePhone in lstCurrentPhone) { PhoneDTO objPhoneDTO = lstUpdatedPhoneDTO.FirstOrDefault(x => x.PhoneId == profilePhone.PhoneId); if (objPhoneDTO != null) { Phone updatedPhone = new Phone { PhoneId = objPhoneDTO.PhoneId, Number = objPhoneDTO.Number }; UpdatePhone(profilePhone.Phone, updatedPhone); } else { DeleteProfilePhone(profilePhone); } } // Save new phones foreach (PhoneDTO phoneDTO in lstNewPhone) { SavePhone(phoneDTO, profile); } }
/// <summary> /// Updates the phone. /// </summary> /// <param name="phone">The phone.</param> /// <returns></returns> public async Task <OperationResultDTO> UpdatePhone(PhoneDTO phone) { var dynamicParameters = new DynamicParameters(); dynamicParameters.Add("@PhoneNumber", phone.PhoneNumber, DbType.String, ParameterDirection.Input); dynamicParameters.Add("@PhoneId", phone.PhoneId, DbType.Int32, ParameterDirection.Input); var results = (await _db.QueryAsync <OperationResultDTO>( "[dbo].[UpdatePhoneNumber]", dynamicParameters, commandType: CommandType.StoredProcedure).ConfigureAwait(false)).FirstOrDefault(); return(results); }
public PhoneDTO Update(PhoneDTO modelDTO) { PhoneDTO returnPhone = null; if (modelDTO != null && modelDTO.PhoneID > 0) { returnPhone = PhoneAssembler.ToDTO(phoneRepo.UpdatePhone(PhoneAssembler.ToEntity(modelDTO))); } return(returnPhone); }
public async Task <IActionResult> AddPhone(PhoneDTO phone) { if (ModelState.IsValid) { var result = await _userServices.AddPhone(phone); return(Ok(result)); } return(BadRequest("Invalid details")); }
public static PhoneDTO PhoneToPhoneDTO(Phone phone) { PhoneDTO objPhoneDTO = new PhoneDTO(); if (phone != null) { objPhoneDTO.PhoneId = phone.PhoneId; objPhoneDTO.Number = phone.Number; } return(objPhoneDTO); }
// POST: odata/Phone public IHttpActionResult Post(PhoneDTO phoneDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // TODO: Add create logic here. // return Created(phoneDTO); return(StatusCode(HttpStatusCode.NotImplemented)); }
public bool InsertPhone(PhoneDTO phone) { if ((phone.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(phone, EntityState.Added); } else { this.ObjectContext.Telefono.AddObject(phone); } return(true); }
public bool UpdatePhone(PhoneDTO phone) { var entity2 = this.ObjectContext.Telefono.FirstOrDefault(row => row.IdContact == Telefono.IdContact); entity2.PhoneNumber = Telefono.PhoneNumber; entity2.PhoneType = Telefono.PhoneType; Context.SaveChanges(); return(true); }