Beispiel #1
0
 public IHttpActionResult Put(CasePC casepc)
 {
     if (casepc.MaCase == null)
     {
         return(BadRequest());
     }
     context.Entry(casepc).State = System.Data.Entity.EntityState.Modified;
     context.SaveChanges();
     return(StatusCode(HttpStatusCode.NoContent));
 }
Beispiel #2
0
        public void Delete(string MaCase)
        {
            if (MaCase == null)
            {
                throw new ArgumentNullException();
            }
            CasePC casepc = context.CasePCs.SingleOrDefault(r => r.MaCase == MaCase);

            context.CasePCs.Remove(casepc);
            context.SaveChanges();
        }
Beispiel #3
0
        public void Post(CasePC casepc)
        {
            string ID         = "CS";
            CasePC CasePCLast = new CasePC();

            CasePCLast = context.CasePCs.OrderByDescending(r => r.MaCase).FirstOrDefault();
            string temp = CasePCLast.MaCase.ToString().Substring(2);

            temp = (Int32.Parse(temp) + 1).ToString();
            if (temp.Count() == 4)
            {
                ID = ID + int.Parse(temp);
            }
            else
            if (temp.Count() == 3)
            {
                ID = ID + "0" + int.Parse(temp);
            }
            else
            if (temp.Count() == 2)
            {
                ID = ID + "00" + int.Parse(temp);
            }
            else
            {
                ID = ID + "000" + int.Parse(temp);
            }

            casepc.MaCase = ID;

            CasePC CasePCNeedAdd = new CasePC
            {
                MaCase    = casepc.MaCase,
                Model     = casepc.Model,
                ChieuDai  = Convert.ToInt32(casepc.ChieuDai),
                ChieuRong = Convert.ToInt32(casepc.ChieuRong),
                ChieuCao  = Convert.ToInt32(casepc.ChieuCao),
                HangSX    = casepc.HangSX,
                Giaban    = Convert.ToInt32(casepc.Giaban),
                Diem      = Convert.ToInt32(casepc.Diem),
                DanhGia   = Convert.ToInt32(casepc.DanhGia),
                URL       = casepc.URL
            };

            if (casepc == null)
            {
                throw new ArgumentNullException();
            }
            context.CasePCs.Add(CasePCNeedAdd);
            context.SaveChanges();
        }
Beispiel #4
0
        public CasePC GetByID(string id)
        {
            CasePC proList = new CasePC();
            var    query   = (from prods in context.CasePCs where prods.MaCase == id select prods).ToList();

            foreach (var item in query)
            {
                proList = (new CasePC
                {
                    MaCase = item.MaCase,
                    Model = item.Model,
                    ChieuDai = Convert.ToInt32(item.ChieuDai),
                    ChieuRong = Convert.ToInt32(item.ChieuRong),
                    ChieuCao = Convert.ToInt32(item.ChieuCao),
                    HangSX = item.HangSX,
                    Giaban = Convert.ToInt32(item.Giaban),
                    Diem = Convert.ToInt32(item.Diem),
                    DanhGia = Convert.ToInt32(item.DanhGia),
                    URL = item.URL
                });
            }
            return(proList);
        }