コード例 #1
0
        public async Task <ActionResult> Create([Bind(Include = "MeshId,Name,CustValue,Yeild,Sublimation,MeasureId,ColorMeshId,DataCreate")] Mesh mesh)
        {
            if (ModelState.IsValid)
            {
                try{
                    db.Meshes.Add(mesh);
                    await db.SaveChangesAsync();
                }
                catch (System.Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.InnerException != null &&
                        ex.InnerException.InnerException.Message.Contains("Mesh_Name_Index"))
                    {
                        ModelState.AddModelError(string.Empty, "Não é possível inserir com o mesmo nome!");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }

                    ViewBag.MeasureId   = new SelectList(CombosHelper.GetMeasures(), "MeasureId", "Name", mesh.MeasureId);
                    ViewBag.ColorMeshId = new SelectList(CombosHelper.GetColors(), "ColorMeshId", "Color", mesh.ColorMeshId);
                    return(View(mesh));
                }
            }

            ViewBag.ColorMeshId = new SelectList(CombosHelper.GetColors(), "ColorMeshId", "Color", mesh.ColorMeshId);
            ViewBag.MeasureId   = new SelectList(CombosHelper.GetMeasures(), "MeasureId", "Name", mesh.MeasureId);
            return(View(mesh));
        }
コード例 #2
0
        public async Task <ActionResult> Create([Bind(Include = "PrintSizeId,Name,SizeX,SizeY,ValueSize,MeasureId,DataCreate")] PrintSize printSize)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    db.PrintSizes.Add(printSize);
                    await db.SaveChangesAsync();
                }

                catch (System.Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.InnerException != null &&
                        ex.InnerException.InnerException.Message.Contains("PrintSize_Name_Index"))
                    {
                        ModelState.AddModelError(string.Empty, "Não é possível inserir com o mesmo nome!");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }

                    ViewBag.MeasureId = new SelectList(CombosHelper.GetMeasures(), "MeasureId", "Name", printSize.MeasureId);

                    return(View(printSize));
                }

                return(RedirectToAction("Index"));
            }

            return(View(printSize));
        }
コード例 #3
0
        public async Task <ActionResult> Create(ClientViewModel client)
        {
            if (ModelState.IsValid)
            {
                //Inicia o valor de AvailableCredit como 0,00
                client.Clients.AvailableCredit = 0;
                client.Clients.DataCreate      = DateTime.Now;

                /*
                 * Tratando fotografia, pego o arquivo que vem em photoFile,
                 * faço o upload, a após pego o endereco de armazenamento.
                 */
                var pic    = string.Empty;
                var folder = "~/Content/PhotosPerfil";
                if (client.Clients.PhotoFile != null)
                {
                    pic = FilesHelper.UploadPhoto(client.Clients.PhotoFile, folder);
                    pic = string.Format("{0}/{1}", folder, pic);
                }
                client.Clients.Photo = pic;

                try
                {
                    db.People.Add(client.Clients);
                    await db.SaveChangesAsync();
                }
                catch (System.Exception)
                {
                    ModelState.AddModelError(string.Empty, "Não possível adicionar, por ter um item cadastrado com esse mesmo nome!");
                    return(View());

                    throw;
                }

                foreach (var tel in client.Telephones)
                {
                    tel.PersonId = client.Clients.PersonId;
                    db.Telephones.Add(tel);
                    await db.SaveChangesAsync();
                }

                foreach (var address in client.Address)
                {
                    address.PersonId = client.Clients.PersonId;
                    db.Address.Add(address);
                    await db.SaveChangesAsync();
                }
            }

            return(RedirectToAction("Index"));
        }
コード例 #4
0
        public async Task <ActionResult> Create([Bind(Include = "TechnicalPrintId,Name,CustValue")] TechnicalPrint technicalPrint)
        {
            if (ModelState.IsValid)
            {
                try{
                    db.TechnicalPrints.Add(technicalPrint);
                    await db.SaveChangesAsync();
                }
                catch (System.Exception)
                {
                    ModelState.AddModelError(string.Empty, "Não possível adicionar, por ter um item cadastrado com esse mesmo nome!");
                    return(View(technicalPrint));

                    throw;
                }
                return(RedirectToAction("Index"));
            }

            return(View(technicalPrint));
        }
コード例 #5
0
        public async Task <ActionResult> Create([Bind(Include = "ColorMeshId,Color,DataCreate")] ColorMesh colorMesh)
        {
            if (ModelState.IsValid)
            {
                colorMesh.DataCreate = DateTime.Now;

                try{
                    db.ColorMeshes.Add(colorMesh);
                    await db.SaveChangesAsync();
                }
                catch (System.Exception)
                {
                    ModelState.AddModelError(string.Empty, "Não possível adicionar, por ter um item cadastrado com esse mesmo nome!");
                    return(View(colorMesh));

                    throw;
                }
                return(RedirectToAction("Index"));
            }

            return(View(colorMesh));
        }