Esempio n. 1
0
        public ActionResult EditUnit(int?id)
        {
            if (id == null)
            {
                return(View("EditUnit"));
            }
            using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities())
            {
                Units uni = entity.Units.Where(x => x.ID == id).First();
                if (uni == null)
                {
                    return(View("EditUnit"));
                }
                else
                {
                    List <int?> fl = new List <int?>();
                    foreach (UnitsAuctions ua in uni.UnitsAuctions)
                    {
                        fl.Add(ua.AuctionID);
                    }
                    UnitFModel fm = new UnitFModel();
                    fm.unit      = uni;
                    fm.Limitions = fl;

                    return(View("EditUnit", fm));
                }
            }
        }
        /// <summary>
        /// Saves the stored update of a unit into the database,
        /// and sends a cache message of the operation's completion status.
        /// </summary>
        public void editUnitOperation()
        {
            int?id = -1;

            Cache.gen_lock.WaitOne();
            UnitFModel mf = null;

            if (SingletonCache.Instance().Storage.ContainsKey(Context.User.Identity.Name))
            {
                mf = ((UnitFModel)SingletonCache.Instance().Storage[Context.User.Identity.Name]);
            }
            try
            {
                using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities())
                {
                    var original = entity.Units.Find(mf.unit.ID);


                    if (original != null)
                    {
                        entity.UnitsAuctions.RemoveRange(entity.UnitsAuctions.Where(x => x.UnitID == mf.unit.ID));
                        if (mf.Limitations != null)
                        {
                            foreach (int i in mf.Limitations)
                            {
                                UnitsAuctions ua = new UnitsAuctions();
                                ua.AuctionID = i;
                                ua.UnitID    = mf.unit.ID;
                                entity.UnitsAuctions.Add(ua);
                            }
                        }
                        entity.Entry(original).CurrentValues.SetValues(((UnitFModel)SingletonCache.Instance().Storage[Context.User.Identity.Name]).unit);
                        entity.SaveChanges();
                    }
                }
                using (TimchurDatabaseEntities entity2 = new TimchurDatabaseEntities())
                {
                    int strm = mf.unit.ID;
                    id = entity2.Units.Where(x => x.ID == strm).First().ID;
                }
                SingletonCache.Instance().last_msg[Context.User.Identity.Name] = "בפעולה האחרונה, יחידה עודכה במערכת";
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.Write(e.ToString());
                SingletonCache.Instance().last_msg[Context.User.Identity.Name] = "בפעולה האחרונה, עדכון יחידה נכשל במערכת";
            }
            SingletonCache.Instance().Storage[Context.User.Identity.Name] = null;
            Cache.gen_lock.ReleaseMutex();
            string str = Context.User.Identity.Name;
            string msg = "";

            if (SingletonCache.Instance().last_msg.Keys.Contains(str))
            {
                msg = SingletonCache.Instance().last_msg[str];
            }
            string to_s = string.Format("סטאטוס:" + msg);

            Clients.Caller.sendMessage(id.Value.ToString());
        }
Esempio n. 3
0
 public ActionResult EditUnit(UnitFModel uni)
 {
     if (ModelState.IsValid)
     {
         SingletonCache.Instance().Storage[User.Identity.Name] = uni;
         return(RedirectToAction("EUnitLoadingScreen", "Main"));
     }
     else
     {
         return(View(uni));
     }
 }
        /// <summary>
        /// Saves the stored creation of a unit into the database,
        /// and sends a cache message of the operation's completion status.
        /// </summary>
        public void AddUnitOperation()
        {
            int?id = -1;

            Cache.gen_lock.WaitOne();
            UnitFModel mf = ((UnitFModel)SingletonCache.Instance().Storage[Context.User.Identity.Name]);

            try
            {
                using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities())
                {
                    entity.Units.Add(mf.unit);
                    entity.SaveChanges();
                }
                using (TimchurDatabaseEntities entity2 = new TimchurDatabaseEntities())
                {
                    string strm = mf.unit.Name;
                    id = entity2.Units.Where(x => x.Name == strm).First().ID;
                    if (mf.Limitations != null)
                    {
                        foreach (int i in mf.Limitations)
                        {
                            UnitsAuctions ua = new UnitsAuctions();
                            ua.AuctionID = i;
                            ua.UnitID    = id;
                            entity2.UnitsAuctions.Add(ua);
                        }
                    }
                    entity2.SaveChanges();
                }
                SingletonCache.Instance().last_msg[Context.User.Identity.Name] = "בפעולה האחרונה, יחידה נוספה למערכת";
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.Write(e.ToString());
                SingletonCache.Instance().last_msg[Context.User.Identity.Name] = "בפעולה האחרונה, הוספת יחידה נכשלה";
            }
            SingletonCache.Instance().Storage[Context.User.Identity.Name] = null;
            Cache.gen_lock.ReleaseMutex();
            string str = Context.User.Identity.Name;
            string msg = "";

            if (SingletonCache.Instance().last_msg.Keys.Contains(str))
            {
                msg = SingletonCache.Instance().last_msg[str];
            }
            string to_s = string.Format("סטאטוס:" + msg);

            Clients.Caller.sendMessage(id.Value.ToString());
        }
Esempio n. 5
0
 public ActionResult AddUnit(UnitFModel uni)
 {
     if (ModelState.IsValid)
     {
         using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities())
         {
             int cou = entity.Units.Count(x => x.Name == uni.unit.Name);
             if (cou != 0)
             {
                 ModelState.AddModelError("Exist", "יחידה בעלת מספר זה כבר קיים.");
                 return(View(uni));
             }
             else
             {
                 SingletonCache.Instance().Storage[User.Identity.Name] = uni;
                 return(RedirectToAction("UnitLoadingScreen", "Main"));
             }
         }
     }
     else
     {
         return(View(uni));
     }
 }
Esempio n. 6
0
 public ActionResult EUnitLoadingScreen(UnitFModel target)
 {
     return(View(target));
 }