Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        private Phone MappingPhoneDtoToPhone(PhoneDto phoneDto)
        {
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <PhoneDto, Phone>()).CreateMapper();
            var phone  = mapper.Map <PhoneDto, Phone>(phoneDto);

            return(phone);
        }
Exemplo n.º 3
0
        public PhoneDto GetPhone(int phoneId)
        {
            Phone    phone    = Database.Phones.Get(phoneId);
            PhoneDto phoneDto = MappingPhoneToPhoneDto(phone);

            return(phoneDto);
        }
Exemplo n.º 4
0
        private PhoneViewModel MappingPhoneDtoToPhoneViewModel(PhoneDto phoneDto)
        {
            var mapper         = new MapperConfiguration(cfg => cfg.CreateMap <PhoneDto, PhoneViewModel>()).CreateMapper();
            var phoneViewModel = mapper.Map <PhoneDto, PhoneViewModel>(phoneDto);

            return(phoneViewModel);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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"));
        }
Exemplo n.º 7
0
        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();
            }
        }
Exemplo n.º 8
0
        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));
            }
        }
Exemplo n.º 9
0
        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));
            }
        }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
        public int Create(PhoneDto phoneDto)
        {
            Phone phone = MappingPhoneDtoToPhone(phoneDto);

            Database.Phones.Create(phone);
            Database.Save();
            return(phone.Id);
        }
Exemplo n.º 12
0
        public async Task <IActionResult> UpdateAsync([FromBody] PhoneDto model, [FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(ReturnResult(await _phoneService.UpdateAsync(model, id)));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> AddAsync([FromBody] PhoneDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(ReturnResult(await _phoneService.AddAsync(model)));
        }
Exemplo n.º 14
0
        public bool ValidatePhoneDto(PhoneDto phoneDto)
        {
            if (string.IsNullOrEmpty(phoneDto.NationalNumber))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 15
0
        public async Task <HttpResponseMessage> GetBySlug(string slug)
        {
            HttpResponseMessage response = null;

            PhoneDto phone = _phonesService.GetPhone(slug);

            response = Request.CreateResponse(HttpStatusCode.OK, phone);

            return(response);
        }
Exemplo n.º 16
0
        // 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);
        }
Exemplo n.º 17
0
        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
            });
        }
Exemplo n.º 19
0
        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"));
        }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
 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;
     }
 }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
0
        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));
        }
Exemplo n.º 24
0
 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));
     }
 }
Exemplo n.º 25
0
        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);
            }
        }
Exemplo n.º 26
0
        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"));
        }
Exemplo n.º 27
0
        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;
            }
        }
Exemplo n.º 28
0
        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);
        }
Exemplo n.º 29
0
        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);
            }
        }
Exemplo n.º 30
0
        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;
        }
Exemplo n.º 31
0
        /// <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 }
            };
        }