public bool UpdateQuantityEquipmentForEdit(EquipmentUsingHistory eq)
        {
            try
            {
                Equipment             e       = new EquipmentDAO().GetEquipmentById(eq.EquipmentId);
                EquipmentUsingHistory current = new EquipmentUsingHistoryDAO().GetEquipment(eq.SceneId, eq.EquipmentId);

                if (eq.Quantity > current.Quantity)
                {
                    e.Quantity = e.Quantity - (eq.Quantity - current.Quantity);
                }
                else
                {
                    e.Quantity = e.Quantity + (current.Quantity - eq.Quantity);
                }

                new EquipmentDAO().UpdateEquipment(e);
            }

            catch (Exception)
            {
                throw;
            }
            return(true);
        }
 public bool UpdateQuantityEquipment(EquipmentUsingHistory eq, bool isPush)
 {
     try
     {
         Equipment e = new EquipmentDAO().GetEquipmentById(eq.EquipmentId);
         if (e != null)
         {
             if (isPush)
             {
                 e.Quantity = e.Quantity + eq.Quantity;
             }
             else
             {
                 e.Quantity = e.Quantity - eq.Quantity;
             }
             new EquipmentDAO().UpdateEquipment(e);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         throw;
     }
     return(true);
 }
        public bool AddNew(EquipmentUsingHistory rc)
        {
            using (var db = new JOURNEYTOTHEWESTEntities())
            {
                try
                {
                    UpdateQuantityEquipment(rc, false);
                    db.EquipmentUsingHistories.Add(rc);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);

                    throw;
                }
            }
        }
        public bool Update(EquipmentUsingHistory rc)
        {
            using (var db = new JOURNEYTOTHEWESTEntities())
            {
                if (rc != null)
                {
                    try
                    {
                        UpdateQuantityEquipmentForEdit(rc);
                        db.EquipmentUsingHistories.Attach(rc);
                        db.Entry(rc).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        return(false);

                        throw;
                    }
                }
                return(true);
            }
        }
예제 #5
0
        public HttpResponseMessage Update(EquipmentUsingHistory rc)
        {
            var rs = new EquipmentUsingHistoryDAO().Update(rc);

            return(rs == true ? new HttpResponseMessage(HttpStatusCode.OK) : new HttpResponseMessage(HttpStatusCode.BadRequest));
        }