Esempio n. 1
0
        public int CreateColor(ColorDTO colorDTO)
        {
            var param = ParametersHelper.CreateFromObject(colorDTO).IncludeOutputId();

            ExecuteSP("USP_Color_Create", param);
            return(param.GetOutputId());
        }
Esempio n. 2
0
        public IActionResult Modificar(ColorViewModel p_colorVM)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("Error al validar datos.");
                }
                else
                {
                    ColorDTO colorDTO = this._mapper.Map <ColorDTO>(p_colorVM);
                    int      result   = this._colorService.ModificarColor(colorDTO);
                    ViewBag.result = "Accion realizada con exito.";

                    List <ColorViewModel> colorViewModels = this._colorService.getColores()
                                                            .Select(x => this._mapper.Map <ColorViewModel>(x)).ToList();
                    return(View("index", colorViewModels));
                }
            }
            catch (Exception ex)
            {
                ViewBag.error          = ex.InnerException.Message;
                ViewData["accionCRUD"] = AccionesCRUD.MODIFICAR;
                return(View("form", p_colorVM));
            }
        }
        public ColorDTO getColor(int p_id)
        {
            try
            {
                Color objEntity = this._colorRepository.GetById(p_id);
                if (objEntity != null)
                {
                    ColorDTO objResult = new ColorDTO
                    {
                        Id          = objEntity.Id,
                        Codigo      = objEntity.Codigo,
                        Descripcion = objEntity.Descripcion
                    };

                    return(objResult);
                }
                else
                {
                    throw new Exception("No se encontro el registro");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 4
0
        public IActionResult Form([FromQuery] AccionesCRUD accionCRUD, int?Id)
        {
            try
            {
                if (accionCRUD.Equals(AccionesCRUD.AGREGAR) || accionCRUD.Equals(AccionesCRUD.MODIFICAR))
                {
                    ViewData["accionCRUD"] = accionCRUD;
                    if (accionCRUD.Equals(AccionesCRUD.AGREGAR))
                    {
                        return(View());
                    }

                    if (accionCRUD.Equals(AccionesCRUD.MODIFICAR))
                    {
                        ColorDTO       colorDTO       = this._colorService.getColor((int)Id);
                        ColorViewModel colorViewModel = this._mapper.Map <ColorViewModel>(colorDTO);
                        return(View(colorViewModel));
                    }
                }

                throw new Exception("Ocurrio un error inesperado.");
            }
            catch (Exception ex)
            {
                ViewBag.error = ex.Message;
                return(View("index"));
            }
        }
        public async Task <ActionResult> Put(int id, [FromForm] ColorDTO colorDTO)
        {
            var color = _mapper.Map <Color>(colorDTO);

            color.Id = id;
            await _colorService.UpdateColor(color);

            return(NoContent());
        }
Esempio n. 6
0
 public ActionResult Edit([Bind(Include = "Id,Name")] ColorDTO colorDto)
 {
     if (ModelState.IsValid)
     {
         _colorLogic.Edit(colorDto);
         return(RedirectToAction("Index"));
     }
     return(View(colorDto));
 }
        public async Task <ActionResult> Post([FromForm] ColorDTO colorDTO)
        {
            var color = _mapper.Map <Color>(colorDTO);
            await _colorService.InsertColor(color);

            colorDTO = _mapper.Map <ColorDTO>(color);
            var response = new ApiResponse <ColorDTO>(colorDTO);

            return(Created(nameof(Get), new { id = color.Id, response }));
        }
Esempio n. 8
0
        public ActionResult UpdateColor(int id = 0)
        {
            ColorDTO      color = _adminService.GetColor(id);
            CreateColorVM item  = new CreateColorVM()
            {
                Name = color.Name, ColorValue = color.ColorValue
            };

            return(View("CreateColor", color));
        }
Esempio n. 9
0
        public static List <ColorDTO> FindAll()
        {
            var      result   = colorDAL.FindAll();
            ColorDTO colorDTO = new ColorDTO();

            colorDTO.Id   = "CL0";
            colorDTO.Name = "Không biết";
            result.Add(colorDTO);
            return(result);
        }
Esempio n. 10
0
        public static ColorViewModel ToViewModel(this ColorDTO color)
        {
            var colorViewModel = new ColorViewModel
            {
                Id  = color.Id,
                Hex = color.HexValue
            };

            return(colorViewModel);
        }
Esempio n. 11
0
        private void Button_Click_Set_Color(object sender, RoutedEventArgs e)
        {
            if (ColorPickerGridView.SelectedItem != null)
            {
                ColorDTO selectedColor      = ((ColorItem)(ColorPickerGridView.SelectedItem)).color;
                HueCommunicationService hcs = new HueCommunicationService();

                foreach (LightItem lightItem in LightPickerGridView.SelectedItems)
                {
                    hcs.ChangeLightColor(selectedColor, lightItem.LightNumber);
                }
            }
        }
Esempio n. 12
0
 public ActionResult CreateColor(CreateColorVM item)
 {
     if (ModelState.IsValid)
     {
         ColorDTO color = new ColorDTO()
         {
             Name = item.Name, ColorValue = item.ColorValue
         };
         OperationDetails result = _adminService.CreateColor(color);
         ViewBag.Result = result.Message;
         ViewBag.Status = result.Succedeed;
         return(View(item));
     }
     return(View());
 }
        public async Task ensureUpdateColorDeleteFailsForNonExistingMaterial()
        {
            ColorDTO colorDTO = new ColorDTO();

            colorDTO.name  = "lean";
            colorDTO.red   = 1;
            colorDTO.green = 2;
            colorDTO.blue  = 3;
            colorDTO.alpha = 0;

            var response = await client.DeleteAsync(String.Format(urlBase + "/{0}/{1}/{2}", -1, "colors", colorDTO.id));

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.NotNull(response.Content.ReadAsStringAsync());
        }
        public int AgregarColor(ColorDTO p_colorDTO)
        {
            try
            {
                int result = this._colorRepository.Add(new Color
                {
                    Codigo      = p_colorDTO.Codigo,
                    Descripcion = p_colorDTO.Descripcion
                });

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task ensureUpdateColorsDeleteSucceedsWhenOnlyRemovingColor()
        {
            ColorDTO colorDTO = new ColorDTO();

            colorDTO.name  = "lilxan";
            colorDTO.red   = 100;
            colorDTO.green = 200;
            colorDTO.blue  = 10;
            colorDTO.alpha = 0;
            var materialDTO = ensurePostMaterialWorks();

            materialDTO.Wait();

            var response = await client.DeleteAsync(String.Format(urlBase + "/{0}/{1}/{2}", materialDTO.Id, "colors", colorDTO.id));

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
            Assert.NotNull(response.Content.ReadAsStringAsync());
        }
        public async Task ensureUpdateColorPostSucceedsWhenAddingColor()
        {
            ColorDTO colorDTO = new ColorDTO();

            colorDTO.name  = "lean";
            colorDTO.red   = 1;
            colorDTO.green = 2;
            colorDTO.blue  = 3;
            colorDTO.alpha = 0;
            var materialDTO = ensurePostMaterialWorks();

            materialDTO.Wait();

            var response = await client.PostAsJsonAsync(String.Format(urlBase + "/{0}/{1}", materialDTO.Id, "colors"), colorDTO);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.NotNull(response.Content.ReadAsStringAsync());
        }
Esempio n. 17
0
        /// <summary>
        /// Add the color of a material from update
        /// </summary>
        /// <param name="idMaterial">id of the material to be updated</param>
        /// <param name="addColorDTO">ColorDTO with the information of color to add</param>
        /// <returns>boolean true if the update was successful, false if not</returns>
        public AddColorModelView addColor(long idMaterial, ColorDTO addColorDTO)
        {
            MaterialRepository materialRepository = PersistenceContext.repositories().createMaterialRepository();
            Material           material           = materialRepository.find(idMaterial);

            if (addColorDTO != null)
            {
                Color colorToAdd = addColorDTO.toEntity();
                material.addColor(colorToAdd);


                materialRepository.update(material);
                AddColorModelView addColorModelView = new AddColorModelView();
                addColorModelView.color = addColorDTO;
                return(addColorModelView);
            }
            return(null);
        }
        public int ModificarColor(ColorDTO p_colorDTO)
        {
            try
            {
                Color objEntity = this._colorRepository.GetById(p_colorDTO.Id);

                objEntity.Codigo      = p_colorDTO.Codigo;
                objEntity.Descripcion = p_colorDTO.Descripcion;

                int result = this._colorRepository.Update(objEntity);

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <MaterialDTO> ensurePostMaterialWorks()
        {
            MaterialDTO materialDTO = new MaterialDTO();

            materialDTO.designation = "mdf";
            materialDTO.reference   = "bananas" + Guid.NewGuid().ToString("n");
            materialDTO.image       = "image.png";
            ColorDTO colorDTO = new ColorDTO();

            colorDTO.name  = "lilxan";
            colorDTO.red   = 100;
            colorDTO.green = 200;
            colorDTO.blue  = 10;
            colorDTO.alpha = 0;
            ColorDTO otherColorDTO = new ColorDTO();

            otherColorDTO.name  = "another color";
            otherColorDTO.red   = 10;
            otherColorDTO.green = 10;
            otherColorDTO.blue  = 10;
            otherColorDTO.alpha = 10;
            FinishDTO finishDTO      = new FinishDTO();
            FinishDTO otherFinishDTO = new FinishDTO();

            finishDTO.description      = "ola";
            otherFinishDTO.description = "another finish";
            materialDTO.colors         = new List <ColorDTO>(new[] { colorDTO, otherColorDTO });
            materialDTO.finishes       = new List <FinishDTO>(new[] { finishDTO, otherFinishDTO });
            var response = await client.PostAsJsonAsync(urlBase, materialDTO);

            MaterialDTO materialDTOFromPost = JsonConvert.DeserializeObject <MaterialDTO>(await response.Content.ReadAsStringAsync());

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.NotNull(response.Content.ReadAsStringAsync());
            Assert.True(materialDTO.id != -1);
            Assert.Equal(materialDTO.reference, materialDTOFromPost.reference);
            Assert.Equal(materialDTO.image, materialDTOFromPost.image);
            Assert.NotNull(materialDTOFromPost.colors);
            Assert.NotNull(materialDTOFromPost.finishes);
            Assert.Equal(materialDTO.designation, materialDTOFromPost.designation);

            return(materialDTOFromPost);
        }
Esempio n. 20
0
        private async Task <MaterialDTO> createMaterial(string testNumber)
        {
            MaterialDTO materialDTO = new MaterialDTO();

            materialDTO.designation = "Material Designation Test" + testNumber;
            materialDTO.reference   = "Material Reference Test" + testNumber;
            materialDTO.image       = "Material Image Test" + testNumber + ".jpeg";
            ColorDTO  colorDTO       = new ColorDTO();
            ColorDTO  otherColorDTO  = new ColorDTO();
            FinishDTO finishDTO      = new FinishDTO();
            FinishDTO otherFinishDTO = new FinishDTO();

            colorDTO.red               = 100;
            colorDTO.blue              = 100;
            colorDTO.green             = 100;
            colorDTO.alpha             = 10;
            colorDTO.name              = "Color Test" + testNumber;
            otherColorDTO.red          = 150;
            otherColorDTO.blue         = 150;
            otherColorDTO.green        = 150;
            otherColorDTO.alpha        = 100;
            otherColorDTO.name         = "Other Color Test" + testNumber;
            finishDTO.description      = "Finish Test" + testNumber;
            otherFinishDTO.description = "Other Finish Test" + testNumber;
            materialDTO.colors         = new List <ColorDTO>()
            {
                colorDTO, otherColorDTO
            };
            materialDTO.finishes = new List <FinishDTO>()
            {
                finishDTO, otherFinishDTO
            };

            var response = await httpClient.PostAsJsonAsync("mycm/api/materials", materialDTO);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            MaterialDTO createdMaterial =
                await response.Content.ReadAsAsync <MaterialDTO>();

            return(createdMaterial);
        }
 public ActionResult addColor(long idMaterial, [FromBody] ColorDTO addColorDTO)
 {
     try
     {
         AddColorModelView addColorModelView = new core.application.MaterialsController().addColor(idMaterial, addColorDTO);
         if (addColorModelView != null)
         {
             return(Created(Request.Path, addColorModelView));
         }
     }
     catch (NullReferenceException)
     {
         return(BadRequest(new SimpleJSONMessageService(INVALID_REQUEST_BODY_MESSAGE)));
     }
     catch (Exception)
     {
         return(StatusCode(500, UNEXPECTED_ERROR));
     }
     return(BadRequest(new SimpleJSONMessageService(UNABLE_TO_UPDATE_MATERIAL)));
 }
Esempio n. 22
0
 public IActionResult Detalle(int Id)
 {
     try
     {
         ColorDTO colorDTO = this._colorService.getColor((int)Id);
         if (colorDTO != null)
         {
             ColorViewModel colorViewModel = this._mapper.Map <ColorDTO, ColorViewModel>(colorDTO);
             return(View(colorViewModel));
         }
         else
         {
             ViewBag.error = "Ocurrio un erro al intentar obtener el registro solicitado.";
             return(View("index")); //deberia mostrar un msg de notificacion
         }
     }
     catch (Exception ex)
     {
         ViewBag.error = ex.Message;
         return(View("index")); //deberia mostrar un msg de notificacion
     }
 }
Esempio n. 23
0
        public OperationDetails CreateColor(ColorDTO item)
        {
            if (item == null)
            {
                return(new OperationDetails(false, "ОбЪект ссылается на null", this.ToString()));
            }
            Color color = Database.Colors.Find(x => x.Name == item.Name).FirstOrDefault();

            if (color == null)
            {
                color = _mappers.ToColor.Map <ColorDTO, Color>(item);
                Database.Colors.Add(color);
                Database.Save();
                return(new OperationDetails(true, "Цвет был успешно добавлен", this.ToString()));
            }
            else
            {
                Database.Colors.Update(color);
                Database.Save();
                return(new OperationDetails(true, "Цвет был успешно изменён", this.ToString()));
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Creates a new instance of CustomizedMaterial.
        /// </summary>
        /// <param name="addCustomizedMaterialModelView">AddCustomizedMaterialModelView representing the CustomizedMaterial's data.</param>
        /// <returns>An instance of CustomizedMaterial.</returns>
        /// <exception cref="System.ArgumentException">Thrown when no Material could be found with the provided identifier.</exception>
        public static CustomizedMaterial create(AddCustomizedMaterialModelView addCustomizedMaterialModelView)
        {
            MaterialRepository materialRepository = PersistenceContext.repositories().createMaterialRepository();

            Material material = materialRepository.find(addCustomizedMaterialModelView.materialId);

            if (material == null)
            {
                throw new ArgumentException(string.Format(ERROR_UNABLE_TO_FIND_MATERIAL, addCustomizedMaterialModelView.materialId));
            }
            //TODO: replace usage of dto
            FinishDTO finishDTO = addCustomizedMaterialModelView.finish;
            ColorDTO  colorDTO  = addCustomizedMaterialModelView.color;

            if (finishDTO == null && colorDTO == null)
            {
                throw new ArgumentException(NULL_COLOR_AND_FINISH);
            }

            CustomizedMaterial customizedMaterial = null;

            if (finishDTO == null && colorDTO != null)
            {
                customizedMaterial = CustomizedMaterial.valueOf(material, colorDTO.toEntity());
            }
            else if (finishDTO != null && colorDTO == null)
            {
                customizedMaterial = CustomizedMaterial.valueOf(material, finishDTO.toEntity());
            }
            else
            {
                customizedMaterial = CustomizedMaterial.valueOf(material, colorDTO.toEntity(), finishDTO.toEntity());
            }

            return(customizedMaterial);
        }
Esempio n. 25
0
        private void Button_Click_Add_To_Scene(object sender, RoutedEventArgs e)
        {
            if (ColorPickerGridView.SelectedItem != null &&
                LightPickerGridView.SelectedItem != null)
            {
                List <LightItem> lightsInThisPartOfScene = new List <LightItem>();
                // TODO: Optimize this atrocity with a better comparison
                foreach (LightItem li in LightPickerGridView.SelectedItems)
                {
                    foreach (var sceneItem in currentSceneConfig)
                    {
                        if (sceneItem.LightsInScene.Contains(li.LightName))
                        {
                            return;
                        }
                    }
                    lightsInThisPartOfScene.Add(li);
                }

                ColorDTO        selectedColor = ((ColorItem)(ColorPickerGridView.SelectedItem)).color;
                SceneConfigItem sci           = new SceneConfigItem(lightsInThisPartOfScene, selectedColor);
                currentSceneConfig.Add(sci);
            }
        }
Esempio n. 26
0
        public void testToDTO()
        {
            Console.WriteLine("toDTO");
            byte     red   = 1;
            byte     blue  = 1;
            byte     green = 1;
            byte     alpha = 1;
            string   name  = "Cor de Burro quando foge";
            Color    color = Color.valueOf(name, red, green, blue, alpha);
            ColorDTO dto   = new ColorDTO();

            dto.name  = name;
            dto.red   = red;
            dto.green = green;
            dto.blue  = blue;
            dto.alpha = alpha;
            ColorDTO dto2 = color.toDTO();

            Assert.Equal(dto.name, dto2.name);
            Assert.Equal(dto.red, dto2.red);
            Assert.Equal(dto.green, dto2.green);
            Assert.Equal(dto.blue, dto2.blue);
            Assert.Equal(dto.alpha, dto2.alpha);
        }
Esempio n. 27
0
 public async Task Insert(ColorDTO obj)
 {
     var model = _mapper.Map <ColorDTO, Color>(obj);
     await UOW.ColorRepository.Insert(model);
 }
Esempio n. 28
0
        private void btnCounselling_Click(object sender, EventArgs e)
        {
            dgvResult.DataSource = null;
            var            assumptions = new List <string>();
            PurposeDTO     purpose     = (PurposeDTO)cbbPurpose.SelectedItem;
            BrandDTO       brand       = (BrandDTO)cbbBrand.SelectedItem;
            PriceDTO       price       = (PriceDTO)cbbPrice.SelectedItem;
            ColorDTO       color       = (ColorDTO)cbbColor.SelectedItem;
            ObjectUsingDTO objectUsing = (ObjectUsingDTO)cbbObjectUsing.SelectedItem;
            GenderDTO      gender      = (GenderDTO)cbbGender.SelectedItem;

            if (color.Id.Equals("CL0"))
            {
                assumptions.Add(gender.Id.Trim());
            }
            else
            {
                assumptions.Add(color.Id.Trim());
            }
            if (brand.Id.Equals("BR0"))
            {
                assumptions.Add(purpose.Id.Trim());
            }
            else
            {
                assumptions.Add(brand.Id.Trim());
            }
            if (price.Id.Equals("PR0"))
            {
                assumptions.Add(objectUsing.Id.Trim());
            }
            else
            {
                assumptions.Add(price.Id.Trim());
            }


            if (assumptions.Count < 3)
            {
                MessageBox.Show("Bạn cần trả lời thêm câu hỏi để chúng tôi tư vấn!", "Cảnh báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }



            /*if (assumptions.Contains("OS1") && assumptions.Contains("BR4"))
             * {
             *  MessageBox.Show("Bạn cần nhập lại hãng điện thoại hoặc hệ điều hành vì Apple không phải là hệ điều hành Android!", "Lỗi",
             *      MessageBoxButtons.OK, MessageBoxIcon.Error);
             *  return;
             * }*/
            if (assumptions.Contains("OS2") && !assumptions.Contains("BR4"))
            {
                MessageBox.Show("Bạn cần nhập lại hãng điện thoại hặc hệ điều hành!", "Lỗi",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var mobiles = ForwardChainingUtil.Result(assumptions);

            if (mobiles.Count == 0)
            {
                MessageBox.Show("Chúng tôi xin lỗi vì không có loại điện thoại theo mô tả của bạn!", "Thông tin",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.dgvResult.Visible               = true;
            pnResult.Visible                     = true;
            this.dgvResult.DataSource            = mobiles;
            this.dgvResult.Columns["Id"].Visible = false;
        }
Esempio n. 29
0
 public async Task Update(ColorDTO obj)
 {
     var model = _mapper.Map <ColorDTO, Color>(obj);
     await UOW.ColorRepository.Update(model);
 }
Esempio n. 30
0
 public async Task AddAsync(ColorDTO color)
 {
     Color Color = new Color(Guid.NewGuid(), color.Name, color.Description, color.HexCode, color.ImageColorUrl);
     await _colorRepository.AddAsync(_mapper.Map <Color>(color));
 }