public ActionResult DeleteConfirmed(int id)
        {
            ProductPack productPack = this.db.ProductPacks.Find(id);

            this.db.ProductPacks.Remove(productPack);
            this.db.SaveChanges();
            return(this.RedirectToAction("Index"));
        }
Пример #2
0
        public ActionResult MergeProductDuplicate([FromBody] ProductPack pack)
        {
            var primaryId = pack.Duplicates.FirstOrDefault(p => p.IsPrimary).ProductId;

            using (var conn = new NpgsqlConnection(DBProvider.GetConnectionString()))
            {
                conn.Open();

                var req = $@"DO
						$do$
							BEGIN
								IF 0 = (Select COUNT(*) from public.""Product"" Where ""Code"" = '{pack.Code}' limit 1) THEN
									Insert into public.""Product""(""Id"", ""Code"", ""Name"")
									VALUES('{primaryId}', '{pack.Code}', '{pack.Code}');
								ELSIF 0 = (Select COUNT(*) from public.""Product"" Where ""Id"" = '{primaryId}') THEN
									Insert into public.""Product""(""Id"", ""Code"", ""Name"")
									VALUES('{primaryId}', '9999999999', (Select ""Name"" from public.""Product"" Where ""Code"" = '{pack.Code}' limit 1));
								END IF;
							END
						$do$"                        ;

                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = req;
                    cmd.ExecuteNonQuery();
                }

                foreach (var duplicate in pack.Duplicates.Where(p => !p.IsPrimary))
                {
                    var req1 = $@"
					Update public.""PurchaseProduct"" Set ""ProductId"" = '{primaryId}' Where ""ProductId"" = '{duplicate.ProductId}';
					delete from public.""Product"" Where ""Id"" = '{duplicate.ProductId}';
				"                ;

                    using (var cmd = new NpgsqlCommand())
                    {
                        cmd.Connection  = conn;
                        cmd.CommandText = req1;
                        cmd.ExecuteNonQuery();
                    }
                }

                var req2 = $@"
					Update public.""Product"" Set ""Code"" = '{pack.Code}' Where ""Id"" = '{primaryId}'
				"                ;

                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = req2;
                    cmd.ExecuteNonQuery();
                }
            }

            return(Ok());
        }
        // GET: ProductPacks/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductPack productPack = this.db.ProductPacks.Find(id);

            if (productPack == null)
            {
                return(this.HttpNotFound());
            }
            return(this.View(productPack));
        }
        public ActionResult Create(ProductPackInputModel productPack)
        {
            if (this.ModelState.IsValid)
            {
                ProductPack pack = new ProductPack
                {
                    Product         = this.db.Products.First(v => v.ID == productPack.ProductID),
                    Amount          = productPack.Amount,
                    PointOfDelivery = this.db.PointsOfDeliveries.First(v => v.ID == productPack.PointOfDeliveryID)
                };

                this.db.ProductPacks.Add(pack);
                this.db.SaveChanges();
                return(this.RedirectToAction("Index"));
            }

            return(this.View(productPack));
        }
Пример #5
0
 /// <param name="count"> </param>
 /// <param name="productPack">
 /// @return </param>
 public ResultProductPackData(int count, ProductPack productPack, Product product)
 {
     this.Count       = count;
     this.ProductPack = productPack;
     this.Product     = product;
 }