Exemple #1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Positions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPositions(Position position)
 {
     base.AddObject("Positions", position);
 }
Exemple #2
0
        public ActionResult SaveMosaic(PositionViewModel[] positionList)
        {
            if (positionList != null)
            {
                try
                {

                    var MosaicID = positionList[0].MosaicID;
                    var extra = positionList.Where(p => p.Name == "PersonalInfo" || p.Name == "CarInfo"
                                                        || p.Name == "LocationInfo" || p.Name == "BatteryInfo"
                        );

                    
                    var posn = positionList.Except(extra);
                    var mosaic = db.Mosaics.Where(m => m.MosaicID == MosaicID).FirstOrDefault();
                   
                    if (mosaic != null)
                    {
                        mosaic.Updated = DateTime.Now;
                        if (positionList != null)
                            foreach (var positionItem in posn)
                            {
                                
                                Position position =
                                    mosaic.Positions.Where(p => p.Name == positionItem.Name).FirstOrDefault();
                                if (position == null)
                                {

                                    position = new Position();
                                    position.MosaicID = positionItem.MosaicID;
                                    db.Positions.AddObject(position);
                                    db.SaveChanges();
                                }

                                position.Name = positionItem.Name;
                                position.X = (double) positionItem.X;
                                position.Y = (double) positionItem.Y;
                                position.Width = (double) positionItem.Width;
                                position.Height = (double) positionItem.Height;
                                var list = position.PositionMediums.ToList();

                                for (int i = 0; i < list.Count; i++)
                                {
                                    var medium = list[i];
                                     db.PositionMediums.DeleteObject(medium);
                                    list[i] = null;
                                }
                                db.SaveChanges();
                                var order = 0;
                                if (positionItem.MediaUri != null)
                                    foreach (var path in positionItem.MediaUri)
                                    {
                                        if (!String.IsNullOrEmpty(path))
                                       //     if (!position.Media.Any(i => Path.GetFileNameWithoutExtension(i.Name).ToLower().Replace("thumb", "") ==  Path.GetFileNameWithoutExtension(path).ToLower().Replace("thumb", "")))  // Duplicates now allowed
                                            {
                                          // if(order%2==0)  //Deal with duplication bug from js ... Fixed already
                                            {
                                                
                                            
                                                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
                                                if (fileNameWithoutExtension != null)
                                                {
                                                    var nname = fileNameWithoutExtension.ToLower().Replace("thumb", "");

                                                    var newpath = "";
                                                    if(nname.Contains("-crop-"))
                                                    {
                                                        nname = nname.Substring(0,nname.IndexOf("-crop-"));
                                                        var serverpath = HttpContext.Request.Url.GetLeftPart(UriPartial.Authority) +
                   HttpRuntime.AppDomainAppVirtualPath;
                                                        newpath = path.Replace(serverpath, "/");
                                                    }
                                                    //item.Remove("Uploads/Temp/Media/Thumb".Length);
                                                    // name =
                                                    position.PositionMediums.Add(new PositionMedium()
                                                                                     {
                                                                                         Medium =
                                                                                             db.Media.Where(
                                                                                                 m =>
                                                                                                 m.Location.Contains(
                                                                                                     nname)).
                                                                                             FirstOrDefault(),
                                                                                             Options = nname,
                                                                                         Position = position,
                                                                                         Location =!(String.IsNullOrEmpty(newpath)) ?newpath:"",
                                                                                         PlayOrder = (short?) order
                                                                                     });
                                                }
                                                order++;
                                                }
                                            }
                                    }
                            }

                        //Deal With Extras
                        XmlSerializer serializer = new XmlSerializer(typeof(List<PositionViewModel>));
                        var writer = new StringWriter();
                        serializer.Serialize(writer,extra.ToList());
                        mosaic.ExtraData = writer.ToString();
                    }
                    else
                    {
                        return Json("Invalid Mosiac, Please Choose One Before Saving", JsonRequestBehavior.AllowGet);
                    }
                    if (positionList != null && positionList.Count() > 0)
                    {
                        db.SaveChanges();
                        return Json("Sucessfully Saved Mosaic", JsonRequestBehavior.AllowGet);
                    }
                }
                catch (Exception ex)
                {
                    return Json("Error Occured During Save " + ex.Message + " " + ex.StackTrace +(ex.InnerException!=null? ex.InnerException.Message + ex.InnerException.StackTrace:""), JsonRequestBehavior.AllowGet);

                }
               
            }
            return Json("Invalid Mosiac, Please Choose One Before Saving", JsonRequestBehavior.AllowGet);
        }
Exemple #3
0
 /// <summary>
 /// Create a new Position object.
 /// </summary>
 /// <param name="positionID">Initial value of the PositionID property.</param>
 /// <param name="x">Initial value of the X property.</param>
 /// <param name="y">Initial value of the Y property.</param>
 /// <param name="width">Initial value of the Width property.</param>
 /// <param name="height">Initial value of the Height property.</param>
 /// <param name="userID">Initial value of the UserID property.</param>
 public static Position CreatePosition(global::System.Int64 positionID, global::System.Double x, global::System.Double y, global::System.Double width, global::System.Double height, global::System.Int64 userID)
 {
     Position position = new Position();
     position.PositionID = positionID;
     position.X = x;
     position.Y = y;
     position.Width = width;
     position.Height = height;
     position.UserID = userID;
     return position;
 }
Exemple #4
0
        public ActionResult SavePosition(long id, string name, float x = 0, float y = 0, float width = 0, float height = 0, List<string> items = null)
        {
            if (db.Mosaics.Where(m => m.MosaicID == id).Count() > 0)
            {
                var mosaic = db.Mosaics.Where(m => m.MosaicID == id).FirstOrDefault();
                mosaic.Updated = DateTime.Now;
                Position position = null;
                if (mosaic.Positions.Where(p => p.Name == name).Count() > 0)
                {
                    position = mosaic.Positions.Where(p => p.Name == name).FirstOrDefault();
                }
                else
                {
                    position = new Position();
                    position.MosaicID = id;
                    db.Positions.AddObject(position);
                    db.SaveChanges();
                }

                if (position != null)
                {
                    position.Name = name;
                    position.X = x;
                    position.Y = y;
                    position.Width = width;
                    position.Height = height;
                }
                var list = position.PositionMediums.ToList();

                foreach (var medium in list)
                {
                    position.PositionMediums.Remove(medium);

                }
                db.SaveChanges();

                foreach (var item in items)
                {
                    if (!String.IsNullOrEmpty(item))
                        if (position.Media.Where(i => i.Name == item).Count() <= 0)
                        {
                            var nname = Path.GetFileNameWithoutExtension(item).Replace("Thumb", "");
                            //item.Remove("Uploads/Temp/Media/Thumb".Length);
                            // name =
                            position.PositionMediums.Add(new PositionMedium()
                                                             {
                                                                 Medium = db.Media.Where(m => m.Location.Contains(nname)).FirstOrDefault()
                                                                 ,Position = position
                                                             });
                                
                        }
                }

                db.SaveChanges();
                return Json("Sucessfully Saved Position", JsonRequestBehavior.AllowGet);


            }
            else
            {
                return Json("Invalid Mosiac, Please Choose One Before Saving", JsonRequestBehavior.AllowGet);
            }
        }