public void Update(PhoneDto phoneDto) { Phone phone = Database.Phones.Get(phoneDto.Id); phone.Name = phoneDto.Name; phone.BatteryCapacity = phoneDto.BatteryCapacity; phone.Camera = phoneDto.Camera; phone.FrontCamera = phoneDto.FrontCamera; phone.Company = phoneDto.Company; phone.CpuName = phoneDto.CpuName; phone.CpuFrequncy = phoneDto.CpuFrequncy; phone.CpuNumberOfCores = phoneDto.CpuNumberOfCores; phone.Memory = phoneDto.Memory; phone.OperatingSystem = phoneDto.OperatingSystem; phone.Ram = phoneDto.Ram; phone.ScreenDiagonal = phoneDto.ScreenDiagonal; phone.Description = phoneDto.Description; if (phoneDto.Image != null) { phone.Image = phoneDto.Image; } if (phoneDto.Price != 0) { phone.Price = phoneDto.Price; } Database.Phones.Update(phone); Database.Save(); }
private Phone MappingPhoneDtoToPhone(PhoneDto phoneDto) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <PhoneDto, Phone>()).CreateMapper(); var phone = mapper.Map <PhoneDto, Phone>(phoneDto); return(phone); }
public PhoneDto GetPhone(int phoneId) { Phone phone = Database.Phones.Get(phoneId); PhoneDto phoneDto = MappingPhoneToPhoneDto(phone); return(phoneDto); }
private PhoneViewModel MappingPhoneDtoToPhoneViewModel(PhoneDto phoneDto) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <PhoneDto, PhoneViewModel>()).CreateMapper(); var phoneViewModel = mapper.Map <PhoneDto, PhoneViewModel>(phoneDto); return(phoneViewModel); }
private List <PhoneDto> ParsePhones() { var phones = new List <PhoneDto>(); foreach (DataGridViewRow row in dataGridViewPhones.Rows) { var name = row.Cells["textBoxPhoneName"].Value?.ToString(); var price = row.Cells["textBoxPhonePrice"].Value?.ToString(); if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(price)) { break; } var phone = new PhoneDto(); phone.Name = name; phone.Price = Parsers.DecimalParse(price); phone.Description = row.Cells["textBoxPhoneDescription"].Value?.ToString(); phone.Manufacturer = row.Cells["comboBoxPhoneManufacturer"].Value == null ? null : new ProductService.ManufacturerDto { Id = (int)row.Cells["comboBoxPhoneManufacturer"].Value }; phone.RAM = Parsers.IntParse(row.Cells["textBoxPhoneRAM"].Value?.ToString()); phone.ROM = Parsers.IntParse(row.Cells["textBoxPhoneROM"].Value?.ToString()); phone.CPU = row.Cells["textBoxPhoneCPU"].Value?.ToString(); phone.BatteryCapacity = Parsers.IntParse(row.Cells["textBoxPhoneBatteryCapacity"].Value?.ToString()); phone.ScreenDiagonal = Parsers.DoubleParse(row.Cells["textBoxPhoneScreenDiagonal"].Value?.ToString()); phone.Camera = Parsers.DoubleParse(row.Cells["textBoxPhoneCamera"].Value?.ToString()); phones.Add(phone); } return(phones); }
public async Task <IActionResult> AddPhone() { if (!HttpContext.Session.TryGetValue(_constants.SessionTokenKey, out var token)) { return(RedirectToRoute(new { controller = "LoginForm", action = "Index" })); } var phone = new PhoneDto { Name = "Name", Price = 0, Amount = 0, Description = "Description", CompanyName = "Company", }; var response = await _client.PostAsync <Response <bool>, PhoneDto>(phone, $"/api/purchase/addPhone", HttpContext.Session.GetString(_constants.SessionTokenKey)); if (response.IsSuccessStatusCode) { var dataResponse = response.Result; return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }
private void buttonAddPhone_Click(object sender, EventArgs e) { if (textBoxName.Text == string.Empty || textBoxPrice.Text == string.Empty) { errorProviderName.SetError(textBoxName, "Please enter a value to Name field"); errorProviderPrice.SetError(textBoxPrice, "Please enter a value to Price field"); } else { errorProviderName.Clear(); errorProviderPrice.Clear(); PhoneDto phone = new PhoneDto(); phone.Name = textBoxName.Text; phone.Price = Parsers.DecimalParse(textBoxPrice.Text); phone.Description = textBoxDescription.Text; phone.Manufacturer = new ProductService.ManufacturerDto { Id = ((ManufacturerService.ManufacturerDto)comboBoxManufacturer.SelectedItem).Id }; phone.RAM = Parsers.IntParse(textBoxRAM.Text); phone.ROM = Parsers.IntParse(textBoxROM.Text); phone.CPU = textBoxCPU.Text; phone.BatteryCapacity = Parsers.IntParse(textBoxBatteryCapacity.Text); phone.ScreenDiagonal = Parsers.DoubleParse(textBoxScreenDiagonal.Text); phone.Camera = Parsers.DoubleParse(textBoxCamera.Text); _productServiceClient.AddPhone(phone); MessageBox.Show("Book successfully added"); Close(); } }
public ActionResult CreatePhone(PhoneViewModel phoneViewModel, HttpPostedFileBase uploadImage) { try { if (ModelState.IsValid && uploadImage != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(uploadImage.InputStream)) { imageData = binaryReader.ReadBytes(uploadImage.ContentLength); } PhoneDto phoneDto = MappingPhoneViewModelToPhoneDto(phoneViewModel); phoneDto.Image = imageData; int phoneId = phoneService.Create(phoneDto); return(RedirectToAction("CreatePhoneSuccess", new { phoneId })); } return(View(phoneViewModel)); } catch (ValidationException ex) { return(Content(ex.Message)); } }
public ActionResult EditPhone(PhoneViewModel phoneViewModel, HttpPostedFileBase uploadImage) { try { PhoneDto phoneDto = MappingPhoneViewModelToPhoneDto(phoneViewModel); if (uploadImage != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(uploadImage.InputStream)) { imageData = binaryReader.ReadBytes(uploadImage.ContentLength); } phoneDto.Image = imageData; } else { phoneDto.Image = null; } phoneService.Update(phoneDto); PhoneDto phoneDtoUpdated = phoneService.GetPhone(phoneDto.Id); var phoneViewModelUpdated = MappingPhoneDtoToPhoneViewModel(phoneDtoUpdated); return(View("CreatePhoneSuccess", phoneViewModelUpdated)); } catch (ValidationException ex) { return(Content(ex.Message)); } }
public async Task <IHttpActionResult> PostPhoneNumbers(PhoneNumbers phoneNumbers) { var uow = new UnitOfWork <PhoneNumbers>(db); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } uow.Repository.Create(phoneNumbers); uow.Commit(); PhoneDto dto = uow.Repository.ReadAll() .Include(p => p.People) .Select(p => new PhoneDto() { Id = p.Id, PhoneCompany = p.PhoneCompany, PersonId = p.Person_Id, PhoneType = p.PhoneType, PersonName = p.People.LastName + ", " + p.People.FirstName, Number = p.Number }).SingleOrDefault(p => p.Id == phoneNumbers.Id); return(CreatedAtRoute("DefaultApi", new { id = phoneNumbers.Id }, dto)); }
public int Create(PhoneDto phoneDto) { Phone phone = MappingPhoneDtoToPhone(phoneDto); Database.Phones.Create(phone); Database.Save(); return(phone.Id); }
public async Task <IActionResult> UpdateAsync([FromBody] PhoneDto model, [FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(ReturnResult(await _phoneService.UpdateAsync(model, id))); }
public async Task <IActionResult> AddAsync([FromBody] PhoneDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(ReturnResult(await _phoneService.AddAsync(model))); }
public bool ValidatePhoneDto(PhoneDto phoneDto) { if (string.IsNullOrEmpty(phoneDto.NationalNumber)) { return(false); } return(true); }
public async Task <HttpResponseMessage> GetBySlug(string slug) { HttpResponseMessage response = null; PhoneDto phone = _phonesService.GetPhone(slug); response = Request.CreateResponse(HttpStatusCode.OK, phone); return(response); }
// GET: api/Phones/id public async Task <HttpResponseMessage> Get(int id) { HttpResponseMessage response = null; PhoneDto phone = _phonesService.GetPhone(id); response = Request.CreateResponse(HttpStatusCode.OK, phone); return(response); }
public async Task <PhoneDto> AddPhone(Guid id, PhoneDto phoneDto) { var person = await GetEntityByIdAsync(id); var phone = new Phone(person.Id, phoneDto.Number, phoneDto.Type); person.Phones.Add(phone); Repository.Update(person); return(ObjectMapper.Map <Phone, PhoneDto>(phone)); }
internal static PhoneEntity ToEntity(this PhoneDto dto) { if (dto == null) { return(null); } return(new PhoneEntity { TypeId = (int)dto.PhoneType, Number = dto.Number }); }
public async Task <IActionResult> EditPhoneRedirect([FromForm] PhoneDto model) { if (!ModelState.IsValid) { return(RedirectToAction("EditPhone", model)); } var editResult = await _unitOfWork.UserRepo.EditPhone(model); await _unitOfWork.Commit(); return(editResult.Equals(Statuses.Success) ? RedirectToAction("Single", new { id = model.UserId }) : RedirectToAction("Error")); }
public void PhoneValidator() { var validator = new PhoneDtoValidator(); PhoneDto dto = new PhoneDto { Area_code = 123, Country_code = "+55", Number = 123 }; var validated = validator.Validate(dto); Assert.True(validated.IsValid); }
public async Task CreatePhone(PhoneDto phoneDto) { try { Phone phone = Mapper.Map <Phone>(phoneDto); UnitOfWork.Phones.Create(phone); await UnitOfWork.SaveAsync(); } catch (Exception e) { Debug.WriteLine(e); throw; } }
public static ICollection <PhoneDto> MapToPhonesDto(ICollection <Phone> phones) { var phonesDto = new List <PhoneDto>(); foreach (var phone in phones) { var phoneDto = new PhoneDto() { PhoneId = phone.PhoneId, PhoneNumber = phone.PhoneNumber, ContactId = phone.ContactId }; phonesDto.Add(phoneDto); } return(phonesDto); }
public async Task <IActionResult> Edit(PhoneDto editedPhone) { if (!HttpContext.Session.TryGetValue(_constants.SessionTokenKey, out var token)) { return(RedirectToRoute(new { controller = "LoginForm", action = "Index" })); } var response = await _client.PostAsync <Response <bool>, PhoneDto>(editedPhone, $"/api/purchase/updatePhone", HttpContext.Session.GetString(_constants.SessionTokenKey)); if (response.IsSuccessStatusCode) { var dataResponse = response.Result; } return(RedirectToAction("EditPhone", editedPhone)); }
public HttpResponseMessage AddProduct(PhoneDto phone) { try { if (phone != null) { _phoneService.Value.Insert(phone); return(Request.CreateResponse(HttpStatusCode.OK, "Ok")); } return(Request.CreateResponse(HttpStatusCode.BadRequest, "Model is not valid")); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public async Task <string> EditPhone(PhoneDto model) { try { var phone = await _context.Phones.FirstOrDefaultAsync(p => p.Id == model.Id); phone.Type = model.Type; phone.Number = model.Number; _context.Phones.Update(phone); return(Statuses.Success); } catch { return(Statuses.Error); } }
public async Task <IActionResult> GetPhoneCode(PhoneDto phoneDto) { Random random = new Random(); int sayi = random.Next(100000, 999999); var phoneCode = new PhoneNumberCode() { PhoneNumber = phoneDto.PhoneNumber, Code = sayi }; PhoneService.Send(phoneDto.PhoneNumber, sayi); _authRepo.Add(phoneCode); if (await _authRepo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to send the code")); }
public async Task UpdatePhone(int id, PhoneDto phone) { try { Phone actualPhone = UnitOfWork.Phones.Get(id).FirstOrDefault(); Phone newPhone = Mapper.Map <Phone>(phone); Mapper.Map <Phone, Phone>(newPhone, actualPhone); UnitOfWork.Phones.Update(actualPhone); await UnitOfWork.SaveAsync(); } catch (Exception e) { Debug.WriteLine(e); throw; } }
public async Task <ServiceResult <Phone> > AddAsync(PhoneDto phone) { var result = ServiceResult <Phone> .OK(); try { var entity = new Phone(); phone.Update(entity); result.Entity = await _uow.Repository <Phone>().AddAsync(entity); await _uow.SaveAsync(); } catch (Exception e) { result = ServiceResult <Phone> .Error(StringConstants.DatabaseError); } return(result); }
public async Task <string> AddPhone(PhoneDto model) { try { var phone = new Phone { Type = model.Type, Number = model.Number, UserId = model.UserId }; await _context.Phones.AddAsync(phone); return(Statuses.Success); } catch { return(Statuses.Error); } }
public async Task<Phone> Update(PhoneDto phoneDto) { Phone phone = await _phoneRepository.GetById(phoneDto.PhoneId); if (phone != null) { _mapper.Map(phoneDto, phone); phone.Validate(phone, new PhoneValidator()); _notifications.AddNotifications(phone.ValidationResult); if (!_notifications.HasNotifications) { await Put(phone); } } else { _notifications.AddNotification("404", "PhoneId", "Phone with id = " + phoneDto.PhoneId + " not found"); } return phone; }
/// <summary> /// NewVoiceServiceProfile - returns a new VoiceServiceProfileDto based on the values passed in /// </summary> /// <param name="phoneNumber"></param> /// <param name="ig"></param> /// <param name="crv"></param> /// <param name="devID"></param> /// <param name="switchFields"></param> /// <returns></returns> protected static VoiceServiceProfileDto NewVoiceServiceProfile(string phoneNumber, int ig, int crv, string devID, SwitchFieldsDto switchFields) { var phone = new PhoneDto { PhoneNumber = phoneNumber, PhoneProvSpec = new PhoneProvSpecDto { InterfaceGroup = ig, CRV = crv, EquipmentId = devID } }; if (switchFields != null) { phone.PhoneProvSpec.SwitchFields = switchFields; } return new VoiceServiceProfileDto { PhoneLines = new List<PhoneDto> { phone } }; }