예제 #1
0
        public string Save(string Id, int License, int AgentId, string CustomerId)
        {
            try
            {
                var db = new ViewModel.Context.ConnectionStringsContext();

                Models.Cart cart = new Models.Cart
                {
                    AgentId            = AgentId,
                    License            = License,
                    MicrosoftId        = Id,
                    OrderTime          = DateTime.Now,
                    Status             = true,
                    PurchaseUnit       = 2,
                    PurchaseUnitNumber = 12,
                    CustomerId         = CustomerId,
                };

                db.Cart.Add(cart);
                db.SaveChanges();
                return("Successfully Add");
            }
            catch
            {
                return("Unknown error occur, Please try again.");
            }
        }
예제 #2
0
        public List <Models.CartMicrosoftPriceRepo> Get(int AgentId, string CustomerId, bool status = true)
        {
            try
            {
                var db = new ViewModel.Context.ConnectionStringsContext();

                //if (AgentId == 0)  //Get the admin price list
                //{
                var query = (from c in db.Cart
                             join p in db.MicrosoftPriceList
                             on c.MicrosoftId equals p.MicrosoftId
                             where c.AgentId == AgentId && c.Status == status && c.CustomerId == CustomerId
                             select new
                {
                    c.Id,
                    c.License,
                    c.MicrosoftId,
                    c.OrderTime,
                    c.PurchaseUnit,
                    c.PurchaseUnitNumber,
                    p.ResellerPrice,
                    CustomerPrice = AgentId != 0                   //For reseller price list
                                                    ? (db.CustomerPrice.Any(m => m.PriceId == p.Id && m.ResellerId == AgentId))
                                                    ? (db.CustomerPrice.Where(m => m.PriceId == p.Id && m.ResellerId == AgentId)).OrderByDescending(m => m.Id).FirstOrDefault().Price
                                                    : (db.ResellerCustomersPrice.Any(m => m.PriceId == p.Id && m.ResellerId == AgentId && m.CustomerPrice != null)) ?
                                    db.ResellerCustomersPrice.Where(m => m.PriceId == p.Id && m.ResellerId == AgentId).OrderByDescending(m => m.Id).FirstOrDefault().CustomerPrice
                                                    : p.CustomerPrice
                                                    : (db.ResellerCustomersPrice.Any(m => m.PriceId == p.Id && m.ResellerId == 0 && m.CustomerPrice != null)) ?
                                    db.ResellerCustomersPrice.Where(m => m.PriceId == p.Id && m.ResellerId == 0).OrderByDescending(m => m.Id).FirstOrDefault().CustomerPrice
                                                    : p.CustomerPrice,
                    Total = p.CustomerPrice * c.License,
                    Name = p.Name,
                }).ToList();
                //}



                List <Models.CartMicrosoftPriceRepo> list = query.ToList().Select(r => new Models.CartMicrosoftPriceRepo
                {
                    License            = r.License,
                    OrderTime          = r.OrderTime,
                    ResellerPrice      = r.ResellerPrice,
                    MicrosoftId        = r.MicrosoftId,
                    PurchaseUnit       = r.PurchaseUnit,
                    PurchaseUnitNumber = r.PurchaseUnitNumber,
                    Name         = r.Name,
                    ERPrice      = (double)r.CustomerPrice,
                    TotalERPrice = r.Total,
                    Price        = 0,
                    CartId       = r.Id,
                }).ToList();
                return(list);
            }
            catch
            {
                return(new List <Models.CartMicrosoftPriceRepo>());
            }
        }
예제 #3
0
        public string Save(Reseller r)
        {
            string msg = string.Empty;

            try
            {
                var db = new ViewModel.Context.ConnectionStringsContext();
                if (r.Id != 0)   //update
                {
                    var reseller = db.Resellers.Where(m => m.Id == r.Id).SingleOrDefault();
                    reseller.Address     = r.Address;
                    reseller.City        = r.City;
                    reseller.Country     = r.Country;
                    reseller.Email       = r.Email;
                    reseller.FirstName   = r.FirstName;
                    reseller.LastName    = r.LastName;
                    reseller.PhoneNumber = r.PhoneNumber;
                    reseller.ZipCode     = r.ZipCode;
                    reseller.Margin      = r.Margin;
                    msg = "Successfullt Reseller has been updated.";
                }
                else  //Insert
                {
                    if (db.Resellers.Any(m => m.Email == r.Email))
                    {
                        msg = "Email already exist try using another email.";
                    }
                    string          pass     = GeneratePassword.GeneratePassword.AutomaticGeneratePassword(12);
                    Models.Reseller reseller = new Models.Reseller
                    {
                        Address          = r.Address,
                        ZipCode          = r.ZipCode,
                        Status           = true,
                        PhoneNumber      = r.PhoneNumber,
                        City             = r.City,
                        Country          = r.Country,
                        CreatedDate      = DateTime.Now,
                        Email            = r.Email,
                        FirstName        = r.FirstName,
                        LastName         = r.LastName,
                        Password         = pass,
                        Is1stTimePassChg = false,
                        Margin           = r.Margin
                    };
                    db.Resellers.Add(reseller);
                    msg = "Successfully Reseller has been added.";
                    // string Emailbody = r.FirstName + ", " + r.LastName + " now you are our partner.<br /> Here is your password= "******"  <br /> Please <a href='http://" + HttpContext.Current.Request.Url.Authority + "/Reseller/Account/Login/'> Login</a> and change your password";
                    //TMRC_CSP.ViewModel.SendEmail.SendEmailRegister(r.Email, "TMRC Partner", Emailbody);
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                msg = "Unknown error occur, Please try again.";
            }
            return(msg);
        }
예제 #4
0
 //hard delete all of items at once from cart page
 public void DeleteAll(int AgentId)
 {
     try
     {
         var db   = new ViewModel.Context.ConnectionStringsContext();
         var item = db.Cart.Where(m => m.AgentId == AgentId).ToList();
         db.Cart.RemoveRange(item);
         db.SaveChanges();
     }
     catch
     {
     }
 }
예제 #5
0
 //hard deletion of item from cart page
 public string Delete(int id, int AgentId)
 {
     try
     {
         var db   = new ViewModel.Context.ConnectionStringsContext();
         var item = db.Cart.Where(m => m.Id == id && m.AgentId == AgentId).SingleOrDefault();
         db.Cart.Remove(item);
         db.SaveChanges();
         return("Deleted");
     }
     catch
     {
         return("Unknown error occur, Please try again.");
     }
 }
예제 #6
0
        public string UpdateById(int id, int license, string billingFrequency)
        {
            try
            {
                var db = new ViewModel.Context.ConnectionStringsContext();

                var cart = db.Cart.Where(m => m.Id == id && m.Status == true).SingleOrDefault();
                cart.License            = license;
                cart.PurchaseUnit       = 2;
                cart.PurchaseUnitNumber = Convert.ToInt16(billingFrequency.Replace("M", ""));

                db.SaveChanges();
                return("Successfully Updated.");
            }
            catch
            {
                return("Unknown error occur, Please try again.");
            }
        }
예제 #7
0
        public IEnumerable <Models.Reseller> GetActive()
        {
            var db = new ViewModel.Context.ConnectionStringsContext();

            return(db.Resellers.Where(m => m.Status == true).ToList());
        }
예제 #8
0
        public IEnumerable <Models.Reseller> Getlist()
        {
            var db = new ViewModel.Context.ConnectionStringsContext();

            return(db.Resellers.ToList());
        }
예제 #9
0
        public string Buy(int ResellerId, string CustomerId, Int64 InvoiceNo, double DiscountMargin)
        {
            string OffersName = string.Empty;

            using (var db = new ViewModel.Context.ConnectionStringsContext())
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        ViewModel.AddToCart.AddToCart        cart = new ViewModel.AddToCart.AddToCart();
                        List <Models.CartMicrosoftPriceRepo> CartMicrosoftPriceRepo = cart.Get(0, CustomerId, true);

                        //Save the information on sale table
                        Models.Sale sale = new Models.Sale
                        {
                            CustomerId     = CustomerId,
                            InvoiceNo      = InvoiceNo,
                            ResellerId     = ResellerId,
                            SaleDate       = DateTime.Now,
                            DiscountMargin = DiscountMargin
                        };

                        db.Sale.Add(sale);
                        db.SaveChanges();

                        //Save the items in db
                        foreach (var item in CartMicrosoftPriceRepo)
                        {
                            ViewModel.Subscription.Subscriptions subscriptions = new Subscription.Subscriptions(ApplicationDomain.Instance);

                            OffersName += item.Name + ", ";
                            Microsoft.Store.PartnerCenter.Models.Orders.Order order = subscriptions.PlaceOrder(CustomerId, item.MicrosoftId, item.License, Models.PurchaseUnit.Months, item.Name);

                            Models.SaleItems saleItems = new Models.SaleItems
                            {
                                License            = item.License,
                                OfferId            = item.MicrosoftId,
                                OriginalPrice      = (double)System.Math.Round(item.ERPrice, 2),
                                SaleId             = sale.Id,
                                DiscountPrice      = (double)System.Math.Round(item.ERPrice - (item.ERPrice * DiscountMargin) / 100, 2),
                                PurchaseUnitNumber = 0,
                                PurchaseUnit       = 0,
                                OrderId            = order.Id,
                            };
                            db.SaleItems.Add(saleItems);
                            db.SaveChanges();
                        }

                        // If items are sale then remove that items from cart
                        db.Cart.Where(m => m.AgentId == ResellerId && m.Status == true).ToList().ForEach(c => c.Status = false);
                        db.SaveChanges();

                        dbContextTransaction.Commit();

                        //Send email to customer
                        SendEmailOffer(OffersName, CustomerId);


                        return("Successfully Items has been purchased");
                    }
                    catch
                    {
                        dbContextTransaction.Rollback();
                        return("Unknown error occur, Please try again.");
                    }
                }
        }