private void NotThrowAnErrorWhenAddingANewBrand()
 {
     try
     {
         _repository.Add(GetBrand());
     }
     catch (Exception e)
     {
         Assert.Fail(e.ToString(), new StackFrame().GetMethod().Name);
     }
 }
 public IActionResult Create(BrandModel cust)
 {
     ViewData["UserNameM"]  = HttpContext.Session.GetString("name") + " " + HttpContext.Session.GetString("surname");
     ViewData["department"] = HttpContext.Session.GetString("department");
     if (ModelState.IsValid)
     {
         BrandRepository.Add(cust);
         return(RedirectToAction("Index"));
     }
     return(View(cust));
 }
Пример #3
0
        public void GetAllIncludesAllRelationsOfBrand()
        {
            var exteriorColors = new List <ExteriorColor>();
            var interiorColors = new List <InteriorColor>();

            var brand = new Brand
            {
                ExteriorColors = exteriorColors,
                InteriorColors = interiorColors
            };

            _sut.Add(brand);

            var brands = _sut.GetAll();

            Assert.That(brands, Is.Not.Null);

            var brandFromDatabase = brands.FirstOrDefault(b => b.Id == brand.Id);

            Assert.That(brandFromDatabase.ExteriorColors, Is.EqualTo(exteriorColors));
            Assert.That(brandFromDatabase.InteriorColors, Is.EqualTo(interiorColors));
        }
 public HttpResponseMessage Add(HttpRequestMessage request, Brand Brand)
 {
     try
     {
         using (BrandRepository rep = new BrandRepository())
         {
             rep.Add(Brand);
             rep.SaveAll();
         }
         return(request.CreateResponse <Brand>(HttpStatusCode.OK, Brand));
     }
     catch (Exception e)
     {
         return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "Não foi possível inserir usuário [" + e.Message + "]"));
     }
 }
Пример #5
0
        public new bool Add(Brand brand)
        {
            var br = new Brand();

            br.BrandCode    = brand.BrandCode;
            br.UniformCode  = brand.UniformCode;
            br.CustomCode   = brand.CustomCode;
            br.BrandName    = brand.BrandName;
            br.SupplierCode = brand.SupplierCode;
            br.IsActive     = brand.IsActive;
            br.UpdateTime   = DateTime.Now;

            BrandRepository.Add(br);
            BrandRepository.SaveChanges();
            return(true);
        }
Пример #6
0
        private void BrandAddButton_Click(object sender, System.EventArgs e)
        {
            namePictureBox.Visible = false;
            if (brandTextBox.Text.Length == 0)
            {
                namePictureBox.Visible = true;
                return;
            }

            string name = brandTextBox.Text;

            if (this.id != 0)
            {
                BrandRepository.Update(new Brand(this.id, name));
            }
            else
            {
                BrandRepository.Add(name);
            }

            this.Close();
        }
Пример #7
0
        public Pharos.Utility.OpResult SaveOrUpdate(ProductBrand model)
        {
            var obj = BrandRepository.GetQuery(o => o.Title == model.Title && o.Id != model.Id).FirstOrDefault();

            if (obj != null)
            {
                model.BrandSN = obj.BrandSN;
                return(OpResult.Fail("已存在该品牌!"));
            }
            if (model.Id == 0)
            {
                model.BrandSN = MaxSN() + 1;
                model.State   = 1;
                BrandRepository.Add(model);
            }
            else
            {
                var source = BrandRepository.Get(model.Id);
                model.ToCopyProperty(source);
                BrandRepository.SaveChanges();
            }
            return(OpResult.Success());
        }
        public async Task <IActionResult> Post([FromForm] int quantity, [FromForm] string name)
        {
            var brand = new Brand
            {
                Name = name,
            };

            var brandQuantityTimeReceived = new BrandQuantityTimeReceived
            {
                Brand        = brand,
                Quantity     = quantity,
                TimeReseived = DateTime.Now
            };

            brandRepository.Add(brand);
            brandQuantityTimeReceivedRepository.Add(brandQuantityTimeReceived);

            if (await brandRepository.SaveAsync() == 0)
            {
                return(BadRequest());
            }

            return(CreatedAtAction("Post", brand));
        }
Пример #9
0
        public ActionResult SaveOrEdit(Brand brand)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (brand.Id == 0)
                    {
                        BrandRepository.Add(brand);
                    }
                    else
                    {
                        BrandRepository.Edit(brand);
                    }
                    BrandRepository.Save();


                    if (IsSuperAdmin)
                    {
                        return(RedirectToAction("Index", new { storeId = brand.StoreId }));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to save:" + ex.StackTrace);
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return(View(brand));
        }
        public async Task <IActionResult> Upload([FromForm] IFormFile file)
        {
            if (!file.FileName.EndsWith(".tsv"))
            {
                throw new ArgumentNullException("file", "Unsupported file type. The endpoint supports just *.tsv files");
            }

            await using (Stream sr = file.OpenReadStream())
            {
                var buffer = new byte[file.Length];

                await sr.ReadAsync(buffer, 0, (int)file.Length);

                var array = Encoding.UTF8.GetString(buffer).Split('\r');

                var columnArray = array[0].Split('\t');

                int nameIndex;
                int quantityIndex;

                if (columnArray[0].ToLower() == "name")
                {
                    nameIndex     = 0;
                    quantityIndex = 1;
                }
                else
                {
                    nameIndex     = 1;
                    quantityIndex = 0;
                }

                for (var i = 1; i < array.Length; i++)
                {
                    var row = array[i].Split('\t');

                    var brandName     = row[nameIndex];
                    var brandQuantity = Int32.Parse(row[quantityIndex]);

                    var brand = await brandRepository.FindByNameAsync(brandName);

                    if (brand == null)
                    {
                        brand = new Brand
                        {
                            Name = brandName
                        };
                        brandRepository.Add(brand);
                    }

                    var brandQuantityTimeReceived = new BrandQuantityTimeReceived
                    {
                        Brand        = brand,
                        Quantity     = brandQuantity,
                        TimeReseived = DateTime.Now
                    };
                    brandQuantityTimeReceivedRepository.Add(brandQuantityTimeReceived);
                }

                await brandQuantityTimeReceivedRepository.SaveAsync();
            }

            return(Ok());
        }
Пример #11
0
 public IHttpActionResult Create([FromBody] Brand brand)
 {
     brandRepository.Add(brand);
     brandRepository.SaveChanges();
     return(Ok(brand));
 }
Пример #12
0
        private void CopyStoreData(int copyStoreId, int newStoreId)
        {
            StoreDbContext.Configuration.ProxyCreationEnabled = false;


            try
            {
                var items = NavigationRepository.GetNavigationsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    NavigationRepository.Add(s);
                }
                NavigationRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            try
            {
                var items = LocationRepository.GetLocationsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    LocationRepository.Add(s);
                }
                LocationRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            try
            {
                var items = EmailListRepository.GetStoreEmailList(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    EmailListRepository.Add(s);
                }
                EmailListRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            try
            {
                var items = BrandRepository.GetBrandsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    BrandRepository.Add(s);
                }
                BrandRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            try
            {
                var items = ContactRepository.GetContactsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    ContactRepository.Add(s);
                }
                ContactRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            int productCategoryId = 0;

            try
            {
                var items = ProductCategoryRepository.GetProductCategoriesByStoreId(copyStoreId);
                foreach (var productCategory in items)
                {
                    var s = GeneralHelper.DataContractSerialization(productCategory);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    ProductCategoryRepository.Add(s);
                    ProductCategoryRepository.Save();

                    productCategoryId = s.Id;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "ProductCategoryRepository:CopyStore");
            }

            int blogCategoryId = 0;
            int newsCategoryId = 0;

            try
            {
                var items = CategoryRepository.GetCategoriesByStoreId(copyStoreId, StoreConstants.BlogsType);
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    CategoryRepository.Add(s);
                    CategoryRepository.Save();

                    blogCategoryId = s.Id;
                }

                items = CategoryRepository.GetCategoriesByStoreId(copyStoreId, StoreConstants.NewsType);
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    CategoryRepository.Add(s);
                    CategoryRepository.Save();

                    newsCategoryId = s.Id;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }


            try
            {
                var items = ProductRepository.GetProductsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id = 0;
                    s.ProductCategoryId = productCategoryId;
                    s.StoreId           = newStoreId;
                    ProductRepository.Add(s);
                    ProductRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }

            try
            {
                var items = ContentRepository.GetContentsByStoreId(copyStoreId, "", StoreConstants.BlogsType);
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id         = 0;
                    s.StoreId    = newStoreId;
                    s.CategoryId = blogCategoryId;
                    ContentRepository.Add(s);
                    ContentRepository.Save();
                }

                items = ContentRepository.GetContentsByStoreId(copyStoreId, "", StoreConstants.NewsType);
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id         = 0;
                    s.StoreId    = newStoreId;
                    s.CategoryId = newsCategoryId;
                    ContentRepository.Add(s);
                    ContentRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }

            try
            {
                var items = LabelRepository.GetLabelsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    LabelRepository.Add(s);
                    LabelRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }

            try
            {
                var items = ActivityRepository.GetActivitiesByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    ActivityRepository.Add(s);
                    ActivityRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
        }