public IHttpActionResult PutColorSelection(long id, ColorSelection colorSelection)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != colorSelection.Id)
            {
                return(BadRequest());
            }

            db.Entry(colorSelection).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ColorSelectionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutProductTemplate(long id, ProductTemplate productTemplate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != productTemplate.Id)
            {
                return(BadRequest());
            }

            db.Entry(productTemplate).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductTemplateExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "Id,Title,Image,Active")] SampleInspiration sampleInspiration)
 {
     if (ModelState.IsValid)
     {
         SampleInspiration ret = db.SampleInspirations.Where(s => s.Id == sampleInspiration.Id).First();
         ret.Title           = sampleInspiration.Title;
         ret.Active          = sampleInspiration.Active;
         db.Entry(ret).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sampleInspiration));
 }
Ejemplo n.º 4
0
        public IHttpActionResult PutWorkspace(long id, Workspace workspace)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != workspace.Id)
            {
                return(BadRequest());
            }

            if (!Authorized(User, workspace))
            {
                return(Unauthorized());
            }


            CloudStorageProvider imageStorage = new CloudStorageProvider(UserManager);
            var user = UserManager.FindById(User.Identity.GetUserId());

            workspace.Filename = imageStorage.saveImage(user.UserName, assetType, workspace, false);

            db.Entry(workspace).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkspaceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutProduct(long id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.Id)
            {
                return(BadRequest());
            }

            CloudStorageProvider imageStorage = new CloudStorageProvider(UserManager);
            var user = UserManager.FindById(User.Identity.GetUserId());

            product = imageStorage.saveImage(user.UserName, assetType, product, false);

            db.Entry(product).State = EntityState.Modified;
            db.ProductColors.AddRange(product.ProductColors);
            foreach (ProductColor prodColor in product.ProductColors)
            {
                db.Entry(prodColor).State = EntityState.Modified;
            }
            db.ProductTemplates.Add(product.ProductTemplate);
            db.Entry(product.ProductTemplate).State = EntityState.Unchanged;
            db.ProductTemplateColors.AddRange(product.ProductTemplate.ProductTemplateColors);
            foreach (ProductTemplateColor prodTempColor in product.ProductTemplate.ProductTemplateColors)
            {
                db.Entry(prodTempColor).State = EntityState.Unchanged;
            }


            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 6
0
        public ActionResult Edit([Bind(Include = "Id,Title,Image,HasBackgroundImage,BackgroundImage,NumColors,Active")] ProductTemplate productTemplate, HttpPostedFileBase file)
        {
            CloudStorageProvider imageStorage = new CloudStorageProvider(UserManager);

            if (ModelState.IsValid)
            {
                if (file != null && file.ContentLength > 0)
                {
                    productTemplate.FileName = imageStorage.saveImage(UserName, assetType, file);
                }
                else
                {
                    productTemplate.FileName = imageStorage.saveImage(UserName, assetType, productTemplate);
                }
                db.Entry(productTemplate).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(productTemplate));
        }
Ejemplo n.º 7
0
        public ActionResult Edit([Bind(Include = "Id,ProductTemplateId,ColorNumber,InternalColorString,RecolorToleranceUpperLimit,RecolorToleranceLowerLimit,Image")] ProductTemplateColor productTemplateColor, HttpPostedFileBase file)
        {
            CloudStorageProvider imageStorage = new CloudStorageProvider(UserManager);

            if (ModelState.IsValid)
            {
                if (file != null && file.ContentLength > 0)
                {
                    productTemplateColor.FileName = imageStorage.saveImage(UserName, assetType, file);
                }
                else
                {
                    productTemplateColor.FileName = imageStorage.saveImage(UserName, assetType, productTemplateColor);
                }
                db.Entry(productTemplateColor).State = EntityState.Modified;
                db.SaveChanges();
                //return RedirectToAction("Index");
                return(RedirectToAction("Details", "AdminProductTemplates", new { id = productTemplateColor.ProductTemplateId }));
            }
            ViewBag.ProductTemplateId = new SelectList(db.ProductTemplates, "Id", "Title", productTemplateColor.ProductTemplateId);
            return(View(productTemplateColor));
        }
        public IHttpActionResult PutGrid(long id, Grid grid)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != grid.Id)
            {
                return(BadRequest());
            }

            CloudStorageProvider imageStorage = new CloudStorageProvider(UserManager);
            var user = UserManager.FindById(User.Identity.GetUserId());

            grid.Filename = imageStorage.saveImage(user.UserName, assetType, grid, false);

            db.Entry(grid).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GridExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
            //return Ok(grid);
        }
Ejemplo n.º 9
0
        public IHttpActionResult PutSampleInspiration(long id, SampleInspiration sampleInspiration)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != sampleInspiration.Id)
            {
                return(BadRequest());
            }

            CloudStorageProvider imageStorage = new CloudStorageProvider(UserManager);

            sampleInspiration.Filename = imageStorage.saveImage(UserName, assetType, sampleInspiration);


            db.Entry(sampleInspiration).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SampleInspirationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 10
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Used to save a range of Assets from the Compare Screen. </summary>
        ///
        /// <remarks>   Aedmonds, 8/25/2017. </remarks>
        ///
        /// <exception cref="DbUpdateConcurrencyException"> Thrown when a Database Update Concurrency
        ///                                                 error condition occurs. </exception>
        ///
        /// <param name="values">   The values. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        // POST: api/Asset
        public void Post(JObject[] values)
        {
            var user = UserManager.FindById(User.Identity.GetUserId());

            List <Workspace> workspaces = new List <Workspace>();
            List <Grid>      grids      = new List <Grid>();
            List <Product>   products   = new List <Product>();
            List <Asset>     assets     = new List <Asset>();

            foreach (JObject o in values)
            {
                JToken jtoken;
                if (o.TryGetValue("userId", out jtoken))  //Workspace
                {
                    Workspace workspace = JsonConvert.DeserializeObject <Workspace>(o.ToString());
                    workspaces.Add(workspace);
                }
                else if (o.TryGetValue("internalTopLeftColorString", out jtoken))     //Grid
                {
                    Grid grid = JsonConvert.DeserializeObject <Grid>(o.ToString());
                    grids.Add(grid);
                    assets.Add(grid);
                }
                else if (o.TryGetValue("productTemplateId", out jtoken))   //Product
                {
                    Product product = JsonConvert.DeserializeObject <Product>(o.ToString());
                    products.Add(product);
                    assets.Add(product);
                    product.ProductTemplate = db.ProductTemplates.Find(product.ProductTemplate.Id);
                }
            }

            try
            {
                CloudStorageProvider imageStorage = new CloudStorageProvider(UserManager);
                grids      = imageStorage.saveImages(user.UserName, grids);
                products   = imageStorage.saveImages(user.UserName, products);
                workspaces = imageStorage.saveImages(user.UserName, workspaces);

                foreach (Workspace workspace in workspaces)
                {
                    db.Entry(workspace).State = EntityState.Modified;
                }
                foreach (Grid grid in grids)
                {
                    db.Entry(grid).State = EntityState.Modified;
                }
                foreach (Product product in products)
                {
                    db.Entry(product).State = EntityState.Modified;
                    db.Entry(product.ProductTemplate).State = EntityState.Unchanged;
                    foreach (ProductTemplateColor prodTempColor in product.ProductTemplate.ProductTemplateColors)
                    {
                        db.Entry(prodTempColor).State = EntityState.Unchanged;
                    }
                }

                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
            catch (Exception e)
            {
                //TODO: Log error
                throw;
            }
        }