public IActionResult OnPostCreate(string name, IFormFile image)
        {
            MaterialRepository materialRepository = new MaterialRepository();

            try
            {
                Models.Material material = new Models.Material(-1, name, "");
                material.Image = Models.Material.GetFileName(material, image.FileName);
                materialRepository.Create(material);
                if (image != null)
                {
                    using (var fs = new FileStream(_env.WebRootPath + material.Image, FileMode.Create))
                    {
                        image.CopyTo(fs);
                    }
                }
            }
            catch (Exception)
            {
                Message          = "The try to add new material was incorrect!";
                IsWarningMessage = true;
                return(RedirectToPage());
            }
            return(RedirectToPage("Index"));
        }
Ejemplo n.º 2
0
 public async Task CreateMaterial(Models.Material material)
 {
     using (ApplicationDbContext context = new ApplicationDbContext())
     {
         material.Id           = Guid.NewGuid();
         material.SupplierName = context.Supplier.Find(material.Supplier).SupplierName;
         context.Material.Add(material);
         await context.SaveChangesAsync();
     }
 }
Ejemplo n.º 3
0
 private Models.Material getMaterial(Models.Catalogo cat)
 {
     Models.Material material = new Models.Material();
     //material.IdCatalogo = Convert.ToInt32(txtId.Text.Trim());
     material.Catalogo           = cat;
     material.CantidadDisponible = Convert.ToDouble(txtCantidadDisp.Text.Trim());
     material.CantidadInicial    = Convert.ToDouble(txtCantidadInicial.Text.Trim());
     material.Precio             = Convert.ToDouble(txtPrecioTotal.Text.Trim());
     material.PrecioGramo        = Convert.ToDouble(txtPrecioGr.Text.Trim());
     return(material);
 }
Ejemplo n.º 4
0
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     //es recomondable usar otro contexto, aun asi no me funciono
     //Models.Catalogo catalogo = catalogoBindingSource.Current as Models.Catalogo;
     Models.Material material = materialBindingSource.Current as Models.Material;
     using (DBContext context = new DBContext()) {
         context.Entry <Models.Material>(material).State = EntityState.Modified;
         //  context.Entry<Models.Catalogo>(catalogo).State = EntityState.Modified;
         context.SaveChangesAsync();
         MetroFramework.MetroMessageBox.Show(this, "El dato se ha actualizado correctamente");
         dgDatos.Refresh();
         //  cleanInputs();
     }
 }
Ejemplo n.º 5
0
 public async Task EditMaterial(Models.Material material)
 {
     using (ApplicationDbContext context = new ApplicationDbContext())
     {
         var update = context.Material.Find(material.Id);
         if (update != null)
         {
             update.MaterialImage       = material.MaterialImage;
             update.MaterialName        = material.MaterialName;
             update.MaterialDescription = material.MaterialDescription;
             update.Price         = material.Price;
             update.StockQuantity = material.StockQuantity;
             update.Supplier      = material.Supplier;
             update.SupplierName  = context.Supplier.Find(material.Supplier).SupplierName;
             await context.SaveChangesAsync();
         }
     }
 }
Ejemplo n.º 6
0
        public void cleanInputs()
        {
            //Se mueve al ultimo dato de la tabla
            materialBindingSource.MoveLast();
            //Se obtiene el valor del ultimo dato de la tabla
            Models.Catalogo obj  = catalogoBindingSource.Current as Models.Catalogo;
            Models.Material obj2 = materialBindingSource.Current as Models.Material;

            //Se pregunta si es un objeto de base de datos o es uno vacio
            if (obj.IdCatalogo != 0)
            {
                //De ser un objeto de la base de datos, se agrega un nuevo objeto vacio
                catalogoBindingSource.Add(new Models.Catalogo());
                materialBindingSource.Add(new Models.Material());
                //Y se mueve a dicho objeto.
                catalogoBindingSource.MoveLast();
                materialBindingSource.MoveLast();
            }
            btnUpdate.Enabled  = false;
            btnAgregar.Enabled = true;
            btnCancel.Enabled  = false;
        }
Ejemplo n.º 7
0
        public static MvcHtmlString MaterialBadge(Models.Material ma)
        {
            string templ = "<span class =\"badge\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"{0}\">{1}</span>";
            string html  = "";

            switch (ma)
            {
            case Models.Material.HardCover:
                // Use the text block below to separate html elements from code
                html = string.Format(templ, "Hard cover", "HAC");
                break;      // Always break each case

            case Models.Material.SoftCover:
                html = string.Format(templ, "Soft cover", "SOC");
                break;

            case Models.Material.Deluxe:
                html = string.Format(templ, "Deluxe edition", "LUX");
                break;

            case Models.Material.Summary:
                html = string.Format(templ, "Summary", "SUM");
                break;

            case Models.Material.Pocket:
                html = string.Format(templ, "Pocket", "POC");
                break;

            case Models.Material.SeparateBox:
                html = string.Format(templ, "Has separate box", "SEP");
                break;

            default:
                html = string.Format(templ, "", "?");
                break;
            }
            return(MvcHtmlString.Create(html));
        }
Ejemplo n.º 8
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            Models.Catalogo newCatalogo = getInformation();
            Models.Material newMaterial = getMaterial(newCatalogo);

            if (!string.IsNullOrEmpty(newCatalogo.Nombre))
            {
                using (DBContext db = new DBContext())
                {
                    //Para crear encabezado de materia prima
                    db.Catalogos.Add(newCatalogo);
                    db.Materials.Add(newMaterial);
                    db.SaveChangesAsync();

                    //Notificar que el dato se aguardo correctamente
                    MetroFramework.MetroMessageBox.Show(this, "El dato se ha agrego correctamente");

                    //Refrescar el grid y traer los datos de la base
                    loadData();
                    cleanInputs();
                }
            }
        }
Ejemplo n.º 9
0
 public static Material ToDomainModel(this Models.Material product)
 {
     return(new Material(product.Name, product.Description, product.Price));
 }
Ejemplo n.º 10
0
 private bool MaterialExistsAndIsValid(Models.Material material)
 {
     return(this._context.Materials.Any(m =>
                                        m.Name == material.Name &&
                                        m.ExpirationDate == null));
 }
Ejemplo n.º 11
0
        public Models.Volume BuildVolume(Server.Models.Volume volume)
        {
            var modelVolume = new Volume();

            modelVolume.VolumeId = volume.VolumeId;

            if (volume.HomeLocation != null)
            {
                var homeAddress = new Models.Address
                {
                    AddressId      = volume.HomeLocation.AddressId,
                    Street         = volume.HomeLocation.Street,
                    AdditionalInfo = volume.HomeLocation.AdditionalInfo,
                    Zip            = volume.HomeLocation.ZipCode,
                    City           = volume.HomeLocation.Zip.City
                };
                modelVolume.HomeLocation   = homeAddress;
                modelVolume.HomeLocationId = volume.HomeLocationId;
            }

            if (volume.CurrentLocation != null)
            {
                var currentAddress = new Models.Address
                {
                    AddressId      = volume.CurrentLocation.AddressId,
                    Street         = volume.CurrentLocation.Street,
                    AdditionalInfo = volume.CurrentLocation.AdditionalInfo,
                    Zip            = volume.CurrentLocation.ZipCode,
                    City           = volume.CurrentLocation.Zip.City
                };
                modelVolume.CurrentLocation   = currentAddress;
                modelVolume.CurrentLocationId = volume.CurrentLocationId;
            }

            if (volume.Material != null)
            {
                var volumeMaterial = new Models.Material
                {
                    MaterialId  = volume.MaterialId,
                    Isbn        = volume.Material.Isbn,
                    Language    = volume.Material.Language,
                    Lendable    = volume.Material.Lendable,
                    Description = volume.Material.Description,
                };
                if (volume.Material.MaterialAuthors != null)
                {
                    var authors = volume.Material.MaterialAuthors.Select(e => new Models.Author
                    {
                        AuthorId  = e.Author.AuthorId,
                        FirstName = e.Author.FirstName,
                        LastName  = e.Author.LastName
                    }).ToList();
                    volumeMaterial.Authors = authors;
                }
                if (volume.Material.MaterialSubjects != null)
                {
                    var materialSubjects = volume.Material.MaterialSubjects.Select(e => new Models.MaterialSubject
                    {
                        SubjectId   = e.MaterialSubject.SubjectId,
                        SubjectName = e.MaterialSubject.SubjectName
                    }).ToList();
                    volumeMaterial.MaterialSubjects = materialSubjects;
                }
                modelVolume.Material   = volumeMaterial;
                modelVolume.MaterialId = volume.MaterialId;
            }


            return(modelVolume);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Se carga el listado de materiales
        /// </summary>
        /// <returns>Lista Materiales</returns>
        public static Models.Material CargaMaterial(string idMaterial)
        {
            object[] paramArray = new object[2];
            try
            {
                paramArray[0] = idMaterial == "" ? null : idMaterial;
                paramArray[1] = null;
                            
                var db = DatabaseFactory.CreateDatabase("SQLStringConn");

                using (IDataReader dataReader = db.ExecuteReader("usp_CargarMateriales", paramArray))
                {
                    while (dataReader.Read())
                    {
                        var objMaterial = new Models.Material()
                        {
                            id = Convert.ToInt32(dataReader["idMaterial"]),
                            NombreMaterial = Convert.ToString(dataReader["nombreMaterial"]),
                            AnchoMaterial = Convert.ToInt32(dataReader["anchoMaterial"]),
                            AnchoUM = Convert.ToInt32(dataReader["idUMAncho"]),
                            LargoMaterial = Convert.ToInt32(dataReader["largoMaterial"]),
                            LargoUM = Convert.ToInt32(dataReader["idUMLargo"]),
                            PesoMaterial = Convert.ToInt32(dataReader["pesoMaterial"]),
                            PesoUM = Convert.ToInt32(dataReader["idUMPeso"]),
                            CalidadMaterial = Convert.ToString(dataReader["calidadMaterial"]),
                            TipoMaterial = Convert.ToInt32(dataReader["idTipoMaterial"]),
                            Grupo = Convert.ToInt32(dataReader["idGrupo"]),
                            Observaciones = Convert.ToString(dataReader["observacionesMaterial"]),
                            Estatus = Convert.ToString(dataReader["idEstatus"]),                          
                        };

                        return objMaterial;
                    }
                }
            }
            catch (Exception exp)
            {
                throw new ApplicationException(exp.Message, exp);
            }

            return null;

        }
Ejemplo n.º 13
0
 public ActionResult Nuevo()
 {
     var objMaterial = new Models.Material();
     ViewBag.Titulo = "Nuevo";
     return PartialView("_Nuevo", objMaterial);
 }