Esempio n. 1
0
        public string Proces(DUETContext db, dynamic _proces)
        {
            try {
                var index = ((JArray)_proces.index).Select(i => (int)i).ToArray();
                var x     = ((JArray)_proces.x).Select(i => (int)i).ToArray();
                var y     = ((JArray)_proces.y).Select(i => (int)i).ToArray();

                if (x.Length > 0)
                {
                    if (CurrentStamp.Used == false)
                    {
                        CurrentStamp.Used = true;
                        db.Stamps.Update(CurrentStamp);
                        db.SaveChanges();
                    }
                    {
                        for (var i = 0; i < x.Length; i++)
                        {
                            int a     = App.factor(x[i], ViewWidth, Width);
                            int b     = App.factor(y[i], ViewHeight, Height); //square
                            int andex = index[i];

                            Proces proces = new Proces(Id, CurrentStamp.Id, a, b, andex);
                            Processes.Add(proces);
                        }
                        db.SaveChanges();
                    }
                }
                return("");
            }
            catch (Exception exception)
            {
                return("Error in Design Proces: " + exception.Message);
            }
        }
Esempio n. 2
0
        public string CopyDesign(DUETContext db, int designid)
        {
            try
            {
                if (Saved == false)
                {
                    var copydesign = db.Designs.Where(d => d.Id == designid)
                                     .Include(d => d.Member)
                                     .Include(d => d.Processes)
                                     .ThenInclude(p => p.Stamp).First();

                    if (copydesign == null)
                    {
                        return("Error in Design Copy: No design found to copy.");
                    }
                    else
                    {
                        Width  = copydesign.Width;
                        Height = copydesign.Height;

                        Red   = copydesign.Red;
                        Green = copydesign.Green;
                        Blue  = copydesign.Blue;

                        Processes = new List <Proces>();
                        Stamps    = new List <Stamp>();
                        //db.Designs.Update(this);
                        var laststampid = -1;

                        foreach (var copyProces in copydesign.Processes)
                        {
                            Proces proces = new Proces();
                            proces.DesignId = Id;
                            proces.Index    = copyProces.Index;
                            proces.X        = copyProces.X;
                            proces.Y        = copyProces.Y;

                            if (copyProces.StampId != laststampid)
                            {
                                var stamp = new Stamp();
                                stamp.DesignId          = Id;
                                stamp.InspirationId     = copyProces.Stamp.InspirationId;
                                stamp.InspirationWidth  = copyProces.Stamp.InspirationWidth;
                                stamp.InspirationHeight = copyProces.Stamp.InspirationHeight;
                                stamp.Width             = copyProces.Stamp.Width;
                                stamp.Height            = copyProces.Stamp.Height;
                                stamp.X      = copyProces.Stamp.X;
                                stamp.Y      = copyProces.Stamp.Y;
                                stamp.Type   = copyProces.Stamp.Type;
                                stamp.Shape  = copyProces.Stamp.Shape;
                                stamp.Scale  = copyProces.Stamp.Scale;
                                stamp.Rotate = copyProces.Stamp.Rotate;
                                stamp.Red    = copyProces.Stamp.Red;
                                stamp.Green  = copyProces.Stamp.Green;
                                stamp.Blue   = copyProces.Stamp.Blue;
                                stamp.Used   = true;

                                Stamps.Add(stamp);
                                db.Stamps.Add(stamp);
                                db.SaveChanges(); // deze moet anders heb je geen stampId in je proces

                                laststampid = copyProces.StampId;
                            }
                            proces.StampId = laststampid;
                            db.Processes.Add(proces);
                        }

                        db.SaveChanges();
                    }
                    return(GetDesignData(db, designid));
                }
                else
                {
                    return("Error in Design Copy: Your design is already saved. First create a new Design.");
                }
            }
            catch (Exception exception)
            {
                return("Error in Design Copy: " + exception.Message);
            }
        }