Example #1
0
        public bool Update(MobileDTO mobileDTO)
        {
            Mobile mobile = db.Mobiles.Single(mb => mb.Id.Equals(mobileDTO.Id));

            ConvertDataMobile(mobile, mobileDTO);
            db.SubmitChanges();
            return(true);
        }
Example #2
0
        public bool Delete(MobileDTO mobileDTO)
        {
            Mobile mobile = db.Mobiles.Single(mb => mb.Id.Equals(mobileDTO.Id));

            db.Mobiles.DeleteOnSubmit(mobile);
            db.SubmitChanges();
            return(true);
        }
        private void dgvResult_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            var       row       = e.RowIndex;
            string    Id        = dgvResult.Rows[row].Cells[0].Value.ToString();
            MobileDTO mobileDTO = MobileBLL.FindById(Id);

            MessageBox.Show(mobileDTO.ToString(), "Thông tin điện thoại", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #4
0
        public bool Insert(MobileDTO mobileDTO)
        {
            Mobile mobile = new Mobile();

            mobile.Id = mobileDTO.Id;
            ConvertDataMobile(mobile, mobileDTO);
            db.Mobiles.InsertOnSubmit(mobile);
            db.SubmitChanges();
            return(true);
        }
Example #5
0
 private void ConvertDataMobile(Mobile mobile, MobileDTO mobileDTO)
 {
     mobile.Name            = mobileDTO.Name;
     mobile.Price           = mobileDTO.Price;
     mobile.Brand           = mobileDTO.Brand;
     mobile.Color           = mobileDTO.Color;
     mobile.Screen          = mobileDTO.Screen;
     mobile.Ram             = mobileDTO.Ram;
     mobile.Camera          = mobileDTO.Camera;
     mobile.Storage         = mobileDTO.Storage;
     mobile.OperatingSystem = mobileDTO.OperatingSystem;
 }
        public ActionResult Edit(MobileDTO mobileDTO)
        {
            CustomerM    admin       = authService.DecodeJWT(User.Identity.Name);
            ShopMobilesM shopMobiles = shopMobilesService.FindByShopAndMobile(admin.ShopAdminId, mobileDTO.Id);

            if (shopMobiles != null)
            {
                shopMobiles.Price       = mobileDTO.Price;
                shopMobiles.MobilesLeft = mobileDTO.Amount;
                shopMobilesService.Edit(shopMobiles);
            }

            return(RedirectToAction("Manage"));
        }
Example #7
0
        private MobileDTO getMobile()
        {
            MobileDTO mobileDTO = new MobileDTO();

            mobileDTO.Name            = txtName.Text.Trim();
            mobileDTO.Price           = int.Parse(txtPrice.Text.Trim());
            mobileDTO.Brand           = txtBrand.Text.Trim();
            mobileDTO.Color           = txtColor.Text.Trim();
            mobileDTO.Screen          = txtScreen.Text.Trim();
            mobileDTO.Ram             = txtRam.Text.Trim();
            mobileDTO.Camera          = txtCamera.Text.Trim();
            mobileDTO.Storage         = txtStorage.Text.Trim();
            mobileDTO.OperatingSystem = txtOS.Text.Trim();
            return(mobileDTO);
        }
Example #8
0
        public bool SaveMobile(int id, MobileDTO catalogDTO)
        {
            DbContextTransaction transaction = _context.Database.BeginTransaction();
            var check = SaveCatalog(id, transaction, catalogDTO);

            if (!check)
            {
                return(false);
            }
            if (id == 0)
            {
                var mobile = new SpecificationsMobile();
                mobile = CatalogMapper.toSpecificationsMobile(catalogDTO, mobile);
                try
                {
                    _context.SpecificationsMobiles.Add(mobile);
                    _context.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(false);
                }
            }
            else
            {
                var mobile = _context.SpecificationsMobiles.SingleOrDefault(x => x.catalogid == catalogDTO.id);
                if (mobile == null)
                {
                    transaction.Rollback();
                    return(false);
                }
                mobile = CatalogMapper.toSpecificationsMobile(catalogDTO, mobile);
                try
                {
                    _context.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(false);
                }
            }
            return(true);
        }
Example #9
0
        private void dgvProduct_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            var    row = e.RowIndex;
            string Id  = dgvProduct.Rows[row].Cells[0].Value.ToString();

            mobileDTOTemp = MobileBLL.FindById(Id);

            txtName.Text    = mobileDTOTemp.Name;
            txtPrice.Text   = mobileDTOTemp.Price.ToString();
            txtBrand.Text   = mobileDTOTemp.Brand;
            txtColor.Text   = mobileDTOTemp.Color;
            txtScreen.Text  = mobileDTOTemp.Screen;
            txtRam.Text     = mobileDTOTemp.Ram;
            txtCamera.Text  = mobileDTOTemp.Camera;
            txtStorage.Text = mobileDTOTemp.Storage;
            txtOS.Text      = mobileDTOTemp.OperatingSystem;
        }
Example #10
0
 private void btnInsertProduct_Click(object sender, EventArgs e)
 {
     try
     {
         MobileDTO mobileDTO = getMobile();
         mobileDTO.Id = "MB" + (munberOfProduct + 1);
         if (MobileBLL.Insert(mobileDTO))
         {
             MessageBox.Show("Thêm sản phẩm thành công!", "Thông báo",
                             MessageBoxButtons.OK, MessageBoxIcon.Information);
             LoadProduct();
         }
     }
     catch (FormatException ex)
     {
         MessageBox.Show("Lỗi nhập không đúng định dạng!", "Lỗi",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #11
0
 private void btnUpdateProduct_Click(object sender, EventArgs e)
 {
     if (mobileDTOTemp != null)
     {
         MobileDTO mobileDTO = getMobile();
         mobileDTO.Id = mobileDTOTemp.Id;
         if (MobileBLL.Update(mobileDTO))
         {
             MessageBox.Show("Cập nhật sản phẩm thành công!", "Thông báo",
                             MessageBoxButtons.OK, MessageBoxIcon.Information);
             LoadProduct();
         }
     }
     else
     {
         MessageBox.Show("Bạn chưa chọn sản phẩm cần cập nhật!", "Cảnh báo",
                         MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Example #12
0
 private void btnRemoveProduct_Click(object sender, EventArgs e)
 {
     if (mobileDTOTemp != null)
     {
         if (MobileBLL.Delete(mobileDTOTemp))
         {
             MessageBox.Show("Xóa sản phẩm thành công!", "Thông báo",
                             MessageBoxButtons.OK, MessageBoxIcon.Information);
             LoadProduct();
             mobileDTOTemp = null;
             ClearTextBoxes();
         }
     }
     else
     {
         MessageBox.Show("Bạn chưa chọn sản phẩm cần xóa!", "Cảnh báo",
                         MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Example #13
0
 public static SpecificationsMobile toSpecificationsMobile(MobileDTO mobileDTO, SpecificationsMobile mobile)
 {
     try
     {
         mobile.backcamera     = mobileDTO.backcamera;
         mobile.frontcamera    = mobileDTO.frontcamera;
         mobile.internalmemory = mobileDTO.internalmemory;
         mobile.memorystick    = mobileDTO.memorystick;
         mobile.sim            = mobileDTO.sim;
         mobile.batery         = mobileDTO.batery;
         mobile.createdAt      = mobileDTO.id > 0 ? mobile.createdAt : DateTime.Now;
         mobile.updatedAt      = DateTime.Now;
         mobile.catalogid      = mobileDTO.id;
         return(mobile);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Example #14
0
 public static bool Delete(MobileDTO mobileDTO)
 {
     return(mobileDAL.Delete(mobileDTO));
 }
Example #15
0
 public static bool Update(MobileDTO mobileDTO)
 {
     return(mobileDAL.Update(mobileDTO));
 }
Example #16
0
 public static bool Insert(MobileDTO mobileDTO)
 {
     return(mobileDAL.Insert(mobileDTO));
 }
Example #17
0
        public CatalogDTO GetCatalogById(int id)
        {
            var model = _context.Catalogs.Find(id);

            if (model.catalogtypeid == 1)
            {
                var query = from c in _context.Catalogs
                            join t in _context.CatalogTypes on c.catalogtypeid equals t.id
                            join b in _context.CatalogBrands on c.catalogbrandid equals b.id
                            join sp in _context.Specifications on c.id equals sp.catalogid
                            join sm in _context.SpecificationsMobiles on c.id equals sm.catalogid
                            where c.id == id
                            select new { c, t, b, sp, sm };
                MobileDTO catalog = new MobileDTO();
                foreach (var item in query)
                {
                    catalog.id             = item.c.id;
                    catalog.name           = item.c.name;
                    catalog.pictureuri     = item.c.pictureuri;
                    catalog.price          = item.c.price;
                    catalog.description    = item.c.description;
                    catalog.content        = item.c.content;
                    catalog.quantity       = item.c.quantity;
                    catalog.catalogbrandid = item.c.catalogbrandid;
                    catalog.catalogtypeid  = item.c.catalogtypeid;
                    catalog.cpu            = item.sp.cpu;
                    catalog.ram            = item.sp.ram;
                    catalog.screen         = item.sp.screen;
                    catalog.os             = item.sp.os;
                    catalog.backcamera     = item.sm.backcamera;
                    catalog.frontcamera    = item.sm.frontcamera;
                    catalog.internalmemory = item.sm.internalmemory;
                    catalog.memorystick    = item.sm.memorystick;
                    catalog.sim            = item.sm.sim;
                    catalog.batery         = item.sm.batery;
                }
                return(catalog);
            }
            else
            {
                var query = from c in _context.Catalogs
                            join t in _context.CatalogTypes on c.catalogtypeid equals t.id
                            join b in _context.CatalogBrands on c.catalogbrandid equals b.id
                            join sp in _context.Specifications on c.id equals sp.catalogid
                            join sl in _context.SpecificationsLaptops on c.id equals sl.catalogid
                            where c.id == id
                            select new { c, t, b, sp, sl };
                LaptopDTO catalog = new LaptopDTO();
                foreach (var item in query)
                {
                    catalog.id             = item.c.id;
                    catalog.name           = item.c.name;
                    catalog.pictureuri     = item.c.pictureuri;
                    catalog.price          = item.c.price;
                    catalog.description    = item.c.description;
                    catalog.content        = item.c.content;
                    catalog.quantity       = item.c.quantity;
                    catalog.catalogbrandid = item.c.catalogbrandid;
                    catalog.catalogtypeid  = item.c.catalogtypeid;
                    catalog.cpu            = item.sp.cpu;
                    catalog.ram            = item.sp.ram;
                    catalog.screen         = item.sp.screen;
                    catalog.os             = item.sp.os;
                    catalog.cardscreen     = item.sl.cardscreen;
                    catalog.connector      = item.sl.connector;
                    catalog.harddrive      = item.sl.harddrive;
                    catalog.design         = item.sl.design;
                    catalog.size           = item.sl.size;
                    catalog.release        = item.sl.release;
                }
                return(catalog);
            }
        }
Example #18
0
        public bool addMobileDTO(MobileDTO catalogDTO)
        {
            using (var dbContextTransaction = db.Database.BeginTransaction())
            {
                try
                {
                    var catalog = new Catalog()
                    {
                        name           = catalogDTO.name,
                        pictureuri     = catalogDTO.pictureuri,
                        price          = catalogDTO.price,
                        description    = catalogDTO.description,
                        content        = catalogDTO.content,
                        quantity       = catalogDTO.quantity,
                        catalogbrandid = catalogDTO.catalogbrandid,
                        catalogtypeid  = catalogDTO.catalogtypeid,
                        createdAt      = DateTime.Now,
                        updatedAt      = DateTime.Now
                    };
                    db.Catalogs.Add(catalog);
                    db.SaveChanges();

                    var id = catalog.id;

                    //specifications
                    var spe = new Specification()
                    {
                        cpu       = catalogDTO.cpu,
                        ram       = catalogDTO.ram,
                        screen    = catalogDTO.screen,
                        os        = catalogDTO.os,
                        createdAt = DateTime.Now,
                        updatedAt = DateTime.Now,
                        catalogid = id
                    };
                    db.Specifications.Add(spe);
                    db.SaveChanges();

                    //mobile
                    var speM = new SpecificationsMobile()
                    {
                        backcamera     = catalogDTO.backcamera,
                        frontcamera    = catalogDTO.frontcamera,
                        internalmemory = catalogDTO.internalmemory,
                        memorystick    = catalogDTO.memorystick,
                        sim            = catalogDTO.sim,
                        batery         = catalogDTO.batery,
                        createdAt      = DateTime.Now,
                        updatedAt      = DateTime.Now,
                        catalogid      = id
                    };
                    db.SpecificationsMobiles.Add(speM);
                    db.SaveChanges();

                    dbContextTransaction.Commit();
                }
                catch (Exception)
                {
                    dbContextTransaction.Rollback();
                    return(false);
                }
            }
            return(true);
        }