Example #1
0
        public ActionResult Create(BackLinkDetail backLinkDetail, Guid id)
        {
            if (ModelState.IsValid)
            {
                Product product = new Product()
                {
                    Id            = Guid.NewGuid(),
                    IsDeleted     = false,
                    IsActive      = backLinkDetail.IsActive,
                    CreationDate  = DateTime.Now,
                    Title         = backLinkDetail.Title,
                    ProductTypeId = db.ProductTypes.FirstOrDefault(c => c.Name == "backlink").Id
                };

                db.Products.Add(product);

                backLinkDetail.ProductId    = product.Id;
                backLinkDetail.BackLinkId   = id;
                backLinkDetail.IsDeleted    = false;
                backLinkDetail.CreationDate = DateTime.Now;
                backLinkDetail.Id           = Guid.NewGuid();
                db.BackLinkDetails.Add(backLinkDetail);
                db.SaveChanges();
                return(RedirectToAction("Index", new{ id = id }));
            }

            ViewBag.BackLinkId = id;
            return(View(backLinkDetail));
        }
Example #2
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            BackLinkDetail backLinkDetail = db.BackLinkDetails.Find(id);

            backLinkDetail.IsDeleted    = true;
            backLinkDetail.DeletionDate = DateTime.Now;

            db.SaveChanges();
            return(RedirectToAction("Index", new { id = backLinkDetail.BackLinkId }));
        }
Example #3
0
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BackLinkDetail backLinkDetail = db.BackLinkDetails.Find(id);

            if (backLinkDetail == null)
            {
                return(HttpNotFound());
            }
            return(View(backLinkDetail));
        }
Example #4
0
        public ActionResult Edit(BackLinkDetail backLinkDetail)
        {
            if (ModelState.IsValid)
            {
                Product product = db.Products.Find(backLinkDetail.ProductId);

                if (product != null)
                {
                    product.Title    = backLinkDetail.Title;
                    product.IsActive = backLinkDetail.IsActive;
                }


                backLinkDetail.IsDeleted       = false;
                db.Entry(backLinkDetail).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", new { id = backLinkDetail.BackLinkId }));
            }
            ViewBag.BackLinkId = backLinkDetail.BackLinkId;
            return(View(backLinkDetail));
        }
        public string UpdateBackLinkDetailPrice()
        {
            List <BackLink> backlinks = db.BackLinks.Where(c => c.IsDeleted == false).ToList();

            foreach (BackLink backlink in backlinks)
            {
                if (backlink.OneMonthBackLink != null)
                {
                    Product product = new Product()
                    {
                        Id            = Guid.NewGuid(),
                        Title         = backlink.FullName + " 1 ماهه",
                        CreationDate  = DateTime.Now,
                        IsActive      = backlink.IsActive,
                        IsDeleted     = false,
                        ProductTypeId = db.ProductTypes.FirstOrDefault(c => c.Name == "backlink").Id,
                    };

                    db.Products.Add(product);


                    BackLinkDetail backLinkDetail = new BackLinkDetail()
                    {
                        Id           = Guid.NewGuid(),
                        Title        = backlink.FullName + " 1 ماهه",
                        Duration     = 1,
                        ProductId    = product.Id,
                        BackLinkId   = backlink.Id,
                        CreationDate = DateTime.Now,
                        IsDeleted    = false,
                        IsActive     = true,
                        Amount       = backlink.OneMonthBackLink.Value,
                    };

                    db.BackLinkDetails.Add(backLinkDetail);

                    db.SaveChanges();
                }
                if (backlink.ThreeMonthBackLink != null)
                {
                    Product product = new Product()
                    {
                        Id            = Guid.NewGuid(),
                        Title         = backlink.FullName + " 3 ماهه",
                        CreationDate  = DateTime.Now,
                        IsActive      = backlink.IsActive,
                        IsDeleted     = false,
                        ProductTypeId = db.ProductTypes.FirstOrDefault(c => c.Name == "backlink").Id,
                    };

                    db.Products.Add(product);


                    BackLinkDetail backLinkDetail = new BackLinkDetail()
                    {
                        Id           = Guid.NewGuid(),
                        Title        = backlink.FullName + " 3 ماهه",
                        Duration     = 3,
                        ProductId    = product.Id,
                        BackLinkId   = backlink.Id,
                        CreationDate = DateTime.Now,
                        IsDeleted    = false,
                        IsActive     = true,
                        Amount       = backlink.ThreeMonthBackLink.Value,
                    };

                    db.BackLinkDetails.Add(backLinkDetail);

                    db.SaveChanges();
                }
            }


            return(string.Empty);
        }
Example #6
0
        public decimal GetAmountByProductForInsertOrderDetail(Product product)
        {
            decimal amount = 0;

            if (product.ProductType.Name == "reportage")
            {
                Reportage reportage = db.Reportages.FirstOrDefault(c => c.ProductId == product.Id);

                amount = reportage.Price;

                if (reportage.IsInPromotion)
                {
                    if (reportage.DiscountAmount != null)
                    {
                        amount = reportage.DiscountAmount.Value;
                    }
                }

                return(amount);
            }
            else if (product.ProductType.Name == "backlink")
            {
                BackLinkDetail backLinkDetail = db.BackLinkDetails.FirstOrDefault(c => c.ProductId == product.Id);

                if (backLinkDetail != null)
                {
                    amount = backLinkDetail.Amount;
                }
                else
                {
                    amount = 0;
                }


                return(amount);
            }
            else if (product.ProductType.Name == "package")
            {
                ReportageGroup reportageGroup = db.ReportageGroups.FirstOrDefault(c => c.ProductId == product.Id);

                if (reportageGroup != null)
                {
                    if (reportageGroup.Price != null)
                    {
                        amount = reportageGroup.Price.Value;
                    }

                    else
                    {
                        amount = 0;
                    }
                }
                else
                {
                    amount = 0;
                }


                return(amount);
            }
            return(amount);
        }