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));
        }
        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 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));
        }
        private static void GenerateDefaultWorkspace(ApplicationUser user)
        {
            WorkspaceContext db = new WorkspaceContext();
            String           WHITECOLORSTRING = "255,255,255,1";
            Workspace        initWorkspace    = new Workspace();

            initWorkspace.UserId   = user.Email;
            initWorkspace.s        = 1;
            initWorkspace.Filename = Guid.NewGuid().ToString();
            db.Workspaces.Add(initWorkspace);

            ColorSelection initColorSelection = new ColorSelection();

            initColorSelection.WorkspaceId         = initWorkspace.Id;
            initColorSelection.InternalColorString = WHITECOLORSTRING;
            initColorSelection.InternalHSL         = "0,0,0";
            initColorSelection.Favorite            = false;
            db.ColorSelections.Add(initColorSelection);

            for (int i = 0; i < 10; i++)
            {
                initColorSelection                     = new ColorSelection();
                initColorSelection.WorkspaceId         = initWorkspace.Id;
                initColorSelection.InternalColorString = WHITECOLORSTRING;
                initColorSelection.InternalHSL         = "0,0,0";
                initColorSelection.Favorite            = true;
                db.ColorSelections.Add(initColorSelection);
            }
            db.SaveChanges();

            Grid initGrid = new Grid();

            initGrid.WorkspaceId      = initWorkspace.Id;
            initGrid.Width            = 10;
            initGrid.Height           = 10;
            initGrid.HorizontalWeight = 1;
            initGrid.VerticalWeight   = 1;
            initGrid.s = 1;
            initGrid.InternalTopLeftColorString     = WHITECOLORSTRING;
            initGrid.InternalTopRightColorString    = WHITECOLORSTRING;
            initGrid.InternalBottomLeftColorString  = WHITECOLORSTRING;
            initGrid.InternalBottomRightColorString = WHITECOLORSTRING;
            initGrid.Filename = Guid.NewGuid().ToString();
            db.Grids.Add(initGrid);
            db.SaveChanges();
        }
Ejemplo n.º 5
0
        public ActionResult Create([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);
                    db.ProductTemplates.Add(productTemplate);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            return(View(productTemplate));
        }
Ejemplo n.º 6
0
        public ActionResult Create([Bind(Include = "Title,Image,Active")] SampleInspiration sampleInspiration, HttpPostedFileBase file)
        {
            CloudStorageProvider imageStorage = new CloudStorageProvider(UserManager);

            if (ModelState.IsValid)
            {
                if (file != null && file.ContentLength > 0)
                {
                    sampleInspiration.Filename = imageStorage.saveImage(UserName, assetType, file);
                    db.SampleInspirations.Add(sampleInspiration);
                    db.SaveChanges();

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

            return(View(sampleInspiration));
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        public ActionResult Create([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);
                    db.ProductTemplateColors.Add(productTemplateColor);
                    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));
            //return RedirectToAction("Details", "AdminProductTemplates",new { id = productTemplateColor.ProductTemplateId });
        }
        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.º 10
0
        public IHttpActionResult DeleteSharingTemplate(long id)
        {
            Sharing sharingTemplate = db.Sharing.Find(id);

            if (sharingTemplate == null)
            {
                return(NotFound());
            }

            db.Sharing.Remove(sharingTemplate);
            db.SaveChanges();

            return(Ok(sharingTemplate));
        }
Ejemplo n.º 11
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.º 12
0
        /// <summary>
        /// Does a final save of the workspace and closes it
        /// </summary>
        public void Close(bool throwError = false)
        {
            try
            {
                db.SaveChanges();

                Current.DB.Database.Connection.Close();

                Current = null;
            }
            catch (Exception e)
            {
                if (throwError)
                {
                    throw;
                }
            }
        }
        public IHttpActionResult PutSampleRequest(PublicSampleRequest sampleRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                SampleRequest _SampleRequest = db.SampleRequest.SingleOrDefault(r => r.Id == sampleRequest.Id);
                _SampleRequest.Owner          = sampleRequest.Owner;
                _SampleRequest.Notes          = sampleRequest.Notes;
                _SampleRequest.ProjectName    = sampleRequest.ProjectName;
                _SampleRequest.Status         = true;
                _SampleRequest.CreatedDate    = sampleRequest.CreatedDate;
                _SampleRequest.SubmissionDate = sampleRequest.SubmissionDate;
                _SampleRequest.ModifiedDate   = System.DateTime.Now;
                db.SaveChanges();
                //var id = _SampleRequest.Id;

                foreach (SampleRequestAsset _SampleRequestAsset in db.SampleRequestAsset.Where(st => st.RequestId == sampleRequest.Id).ToList())
                {
                    db.SampleRequestAsset.Remove(_SampleRequestAsset);
                    db.SaveChanges();
                }

                foreach (var item in sampleRequest.PublicRequestAssetlist)
                {
                    SampleRequestAsset _SampleRequestAsset = new SampleRequestAsset();
                    _SampleRequestAsset.RequestId = _SampleRequest.Id;
                    _SampleRequestAsset.AssetType = item.AssetType;
                    _SampleRequestAsset.Notes     = item.AssetTitle;
                    _SampleRequestAsset.AssetId   = item.AssetId;
                    db.SampleRequestAsset.Add(_SampleRequestAsset);
                    db.SaveChanges();
                }
            }
            catch (DbUpdateConcurrencyException)
            {
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 14
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;
            }
        }