Beispiel #1
0
        public AssetDto CreateAsset(CreateAssetInput input)
        {
            Asset asset = ObjectMapper.Map <Asset>(input);

            asset = repository.Insert(asset);
            CurrentUnitOfWork.SaveChanges();
            return(ObjectMapper.Map <AssetDto>(asset));
        }
Beispiel #2
0
        public void Create(CreateAssetInput input)
        {
            var @entityAsset = Asset.Create(input.Name, input.Description, input.Code, input.Barcode, input.AdmissionDate, _dateTime.Now, input.Price, input.DepreciationMonthsQty, input.AssetType, input.CategoryId, input.CreatorGuidId, _dateTime.Now, input.Brand, input.ModelStr, input.Plate, input.Series, input.IsAToolInKit, input.CompanyName);

            if (@entityAsset == null)
            {
                throw new UserFriendlyException("No se pudo crear el artículo.");
            }

            if (_assetManager.AssetExist(@entityAsset.Code, input.Id, input.CompanyName))
            {
                throw new UserFriendlyException("Existe un Artículo con el mismo Código.");
            }

            if (input.CustomFieldsDto != null && input.CustomFieldsDto.Any())
            {
                foreach (var cf in input.CustomFieldsDto)
                {
                    var entityCf = CustomField.Create(cf.Name, cf.CustomFieldType, @entityAsset.Id, cf.Value, cf.GetStringValue(), cf.GetDateValue(), cf.GetIntValue(), cf.GetDoubleValue(), input.CreatorGuidId, _dateTime.Now, input.CompanyName);
                    @entityAsset.CustomFields.Add(entityCf);
                }
            }

            if (input.DetailAssetToolKitsDto != null && input.DetailAssetToolKitsDto.Any())
            {
                foreach (var tool in input.DetailAssetToolKitsDto)
                {
                    var entityTool = ToolAsset.Create(tool.Name, tool.Name, tool.Code, @entityAsset.Id, input.CreatorGuidId, _dateTime.Now, tool.Quatity, input.CompanyName);
                    @entityAsset.ToolAssets.Add(entityTool);
                }
            }

            if (HasFile(input.Image))
            {
                string folderPath = "~/AssetsImages/";
                string fileName   = input.Image.FileName;//input.Id + ".png"

                var mappedPath = HostingEnvironment.MapPath(folderPath) + fileName;
                var directory  = new DirectoryInfo(HostingEnvironment.MapPath(folderPath));
                if (directory.Exists == false)
                {
                    directory.Create();
                }
                string folderPathRelative = "../../AssetsImages/";
                input.ImagePath = folderPathRelative + fileName;
                input.Image.SaveAs(mappedPath);

                @entityAsset.SetImage(input.ImagePath);
            }
            _assetManager.Create(@entityAsset);
        }
        public ActionResult Create()
        {
            CreateAssetInput viewModel = new CreateAssetInput();

            viewModel.AdmissionDate = _date.Now;
            try
            {
                viewModel.Categories = _assetService.GetAllCategories(_currentUser.CompanyName);
                //viewModel.Cellars = _assetService.GetAllCellars();
                if (viewModel.Categories != null && viewModel.Categories.Any())
                {
                    viewModel.CategoryId = viewModel.Categories.First().Id;
                }
                viewModel.ErrorCode        = ErrorCodeHelper.None;
                viewModel.ErrorDescription = "";
            }
            catch (Exception e)
            {
                viewModel.ErrorCode        = ErrorCodeHelper.Error;
                viewModel.ErrorDescription = "Error al obtener datos.";
            }
            return(View("_create", viewModel));
        }
Beispiel #4
0
 public AssetDto CreateAsset([FromBody] CreateAssetInput input)
 {
     return(assetAppService.CreateAsset(input));
 }
        public ActionResult Create(IList <string> entity)
        {
            CreateAssetInput viewModel = new CreateAssetInput();

            try
            {
                viewModel = JsonConvert.DeserializeObject <CreateAssetInput>(System.Web.HttpContext.Current.Request["AssetsDataSection"]);
                var imageToUpload = System.Web.HttpContext.Current.Request.Files["AssetsImagesSection"];

                if (ModelState.IsValid)
                {
                    viewModel.Categories = _assetService.GetAllCategories(_currentUser.CompanyName);

                    if (string.IsNullOrEmpty(viewModel.Code))
                    {
                        ModelState.AddModelError("Code", "*Requerido");
                        viewModel.ErrorCode        = ErrorCodeHelper.Error;
                        viewModel.ErrorDescription = "El código es requerido.";
                        return(PartialView("_create", viewModel));
                    }
                    if (string.IsNullOrEmpty(viewModel.Name))
                    {
                        ModelState.AddModelError("Name", "*Requerido");
                        viewModel.ErrorCode        = ErrorCodeHelper.Error;
                        viewModel.ErrorDescription = "El nombre es requerido.";
                        return(PartialView("_create", viewModel));
                    }
                    if (viewModel.Price <= 0)
                    {
                        ModelState.AddModelError("Price", "*Requerido.");
                        viewModel.ErrorCode        = ErrorCodeHelper.Error;
                        viewModel.ErrorDescription = "El precio debe ser mayor que 0.";
                        return(PartialView("_create", viewModel));
                    }
                    if (viewModel.DepreciationMonthsQty <= 0)
                    {
                        ModelState.AddModelError("DepreciationMonthsQty", "*Requerido.");
                        viewModel.ErrorCode        = ErrorCodeHelper.Error;
                        viewModel.ErrorDescription = "La cantidad de meses depreciables debe ser mayor que 0.";
                        return(PartialView("_create", viewModel));
                    }
                    if (viewModel.AdmissionDate > _date.Now)
                    {
                        ModelState.AddModelError("AdmissionDate", "* Error.");
                        viewModel.ErrorCode        = ErrorCodeHelper.Error;
                        viewModel.ErrorDescription = "La fecha de admisión no puede ser mayor a la fecha de hoy.";
                        return(PartialView("_create", viewModel));
                    }

                    if (imageToUpload != null)
                    {
                        viewModel.Image = imageToUpload;
                        if (!CheckImageFormat.IsImage(imageToUpload))
                        {
                            viewModel.ErrorCode        = ErrorCodeHelper.Error;
                            viewModel.ErrorDescription = "Error al cargar la imagen seleccionada, la extensión debe ser de tipo *.jpg, *.png, *.gif, *.jpeg, *.PDF";
                            return(PartialView("_create", viewModel));
                        }
                    }

                    viewModel.CreatorGuidId = _currentUser.CurrentUserId;
                    viewModel.CompanyName   = _currentUser.CompanyName;
                    _assetService.Create(viewModel);
                    ModelState.Clear();
                    var newVm = new CreateAssetInput();
                    newVm.Categories       = _assetService.GetAllCategories(_currentUser.CompanyName);
                    newVm.AdmissionDate    = DateTime.Now;
                    newVm.ErrorCode        = ErrorCodeHelper.Ok;
                    newVm.ErrorDescription = "¡Artículo guardado exitosamente!";
                    return(PartialView("_create", newVm));
                }
                viewModel.Categories       = _assetService.GetAllCategories(_currentUser.CompanyName);
                viewModel.ErrorCode        = ErrorCodeHelper.Error;
                viewModel.ErrorDescription = "Error al intentar guardar los datos.";
                return(PartialView("_create", viewModel));
            }
            catch (Exception e)
            {
                viewModel.Categories       = _assetService.GetAllCategories(_currentUser.CompanyName);
                viewModel.ErrorCode        = ErrorCodeHelper.Error;
                viewModel.ErrorDescription = e.Message;
                return(PartialView("_create", viewModel));
            }
        }