Пример #1
0
        public User editCustomer(User user)
        {
            var obj = db.Users.Where(x => x.IsVerified == true && x.RoleId == 1 && x.Id == user.Id).FirstOrDefault();

            try
            {
                if (user != null)
                {
                    obj.Address         = user.Address;
                    obj.Email           = user.Email;
                    obj.Phone           = user.Phone;
                    obj.StateId         = user.StateId;
                    obj.CountryId       = user.CountryId;
                    obj.DOB             = user.DOB;
                    obj.City            = user.City;
                    obj.LanguageId      = user.LanguageId;
                    obj.GenderId        = user.GenderId;
                    obj.TwitterId       = user.TwitterId;
                    obj.FacebookId      = user.FacebookId;
                    obj.PostalCode      = user.PostalCode;
                    obj.FirstName       = user.FirstName;
                    obj.LastName        = user.LastName;
                    obj.DisplayName     = user.DisplayName;
                    obj.UserName        = user.UserName;
                    obj.MiddleName      = user.MiddleName;
                    db.Entry(obj).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }
            return(obj);
        }
Пример #2
0
        public IActionResult addWithTrans([FromBody] VendorBalance model)
        {
            var result = new VendorTransaction();

            result.IsActive          = true;
            result.IsPaidByPistis    = true;
            result.TransactionDate   = DateTime.Now;
            result.TransactionNumber = model.Transno;
            result.VendorId          = model.VendorId;
            result.AmountPaid        = Convert.ToDecimal(model.Payment);
            db.VendorTransaction.Add(result);
            try
            {
                db.SaveChanges();
                var sum = db.VendorTransactionSummary.Where(x => x.IsActive == true && x.VendorId == model.VendorId).FirstOrDefault();
                if (sum != null)
                {
                    var pending = Convert.ToDecimal(sum.DueAmount - model.Payment);
                    sum.DueAmount       = pending;
                    sum.ModifyOn        = DateTime.Now;
                    db.Entry(sum).State = EntityState.Modified;
                    db.SaveChanges();
                }
                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(Ok(false));
            }
        }
Пример #3
0
 Boolean ReadMsg(List <VendorChatMsg> all, int VendorId)
 {
     if (VendorId != 0)
     {
         foreach (var a in all)
         {
             a.IsVendorRead = true;
         }
     }
     else
     {
         foreach (var a in all)
         {
             a.IsCustomerRead = true;
         }
     }
     try
     {
         db.Entry(all).State = EntityState.Modified;
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Пример #4
0
        public IActionResult refund(decimal amount, int id)
        {
            var data = db.Return.Where(x => x.Id == id && x.IsActive == true).FirstOrDefault();

            if (data != null)
            {
                var check = db.CheckoutItems.Where(x => x.Id == data.CheckoutItemId).FirstOrDefault();
                if (check != null)
                {
                    var tran = db.PaymentTransaction.Where(x => x.CheckoutId == check.CheckoutId).FirstOrDefault();
                    if (tran != null)
                    {
                        var sdk    = sdkdata();
                        var refund = new Refund(sdk);

                        Payment payment = new Payment(sdk);
                        var     pay     = Payment.FindById(Convert.ToInt64(tran.paymentID), sdk);
                        // var refund = new Payment(sdk).Refund();
                        refund.Amount = amount;
                        refund.manualSetPaymentId(Convert.ToDecimal(tran.paymentID));
                        refund.Save();

                        //var r = payment.Refund(amount);
                        if (refund != null)
                        {
                            try
                            {
                                var model = new PaymentTransaction();
                                model.CheckoutId        = tran.CheckoutId;
                                model.intent            = "refund";
                                model.payerID           = tran.payerID;
                                model.ReturnId          = refund.Id.ToString();
                                model.PaymentMethod     = tran.PaymentMethod;
                                model.StatusDetail      = "approved";
                                model.TransactionAmount = amount;
                                model.UserId            = tran.UserId;


                                db.PaymentTransaction.Add(model);
                                db.SaveChanges();


                                //return table
                                data.IsPaid          = true;
                                db.Entry(data).State = EntityState.Modified;
                                db.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                return(Ok(ex));
                            }
                        }
                        return(Ok(refund));
                    }
                }
            }
            return(Ok());
        }
Пример #5
0
        public int RemoveProduct(int Id)
        {
            var message = 0;

            try
            {
                if (Id > 0)
                {
                    var obj = db.CompareProducts.Where(x => x.Id == Id).FirstOrDefault();
                    obj.IsActive        = false;
                    db.Entry(obj).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    db.SaveChanges();
                    message = 1;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(message);
        }
Пример #6
0
        public IActionResult AddToCart([FromBody] Cart pro)
        {
            var model = new Cart();
            var cart  = new Cart();

            //model.AdditionalCost=pro.
            model.IsActive            = true;
            model.IsConvertToCheckout = false;
            model.OrderDate           = DateTime.Now;
            // model.TotalAmount = pro.TotalAmount;
            if (pro.UserId > 0)
            {
                model.UserId = pro.UserId;
                cart         = db.Carts.Where(x => x.UserId == pro.UserId && x.IsActive == true && x.IsConvertToCheckout == false).FirstOrDefault();
            }
            else
            {
                cart = db.Carts.Where(x => x.IpAddress == pro.IpAddress && x.UserId == null && x.IsActive == true && x.IsConvertToCheckout == false).FirstOrDefault();
            }

            model.IpAddress = pro.IpAddress;
            //model.VendorId
            try
            {
                if (cart == null)
                {
                    db.Carts.Add(model);
                    db.SaveChanges();
                    model.OrderNumber = "ORD-" + CommonFunctions.RandCode(model.Id);
                    db.SaveChanges();
                    //Addto cartitem
                    var item = new CartItem();
                    item.IsActive = true;
                    item.ProductVariantDetailId = pro.CartItems[0].ProductVariantDetailId;

                    item.Quantity = pro.CartItems[0].Quantity == 0?1:pro.CartItems[0].Quantity;

                    item.UnitId   = 1;
                    item.VendorId = pro.CartItems[0].VendorId;
                    item.CartId   = model.Id;
                    db.CartItems.Add(item);
                    db.SaveChanges();

                    ////TotalAmount withCommission in cart
                    //var cartdata = db.Carts.Where(x => x.Id == model.Id).FirstOrDefault();
                    //cartdata.TotalAmount = item.Amount;
                    //db.SaveChanges();
                }
                else
                {//update
                    model.Id = cart.Id;
                    var cartitem = db.CartItems.Where(x => x.CartId == model.Id && x.ProductVariantDetailId == pro.CartItems[0].ProductVariantDetailId && x.IsActive == true).FirstOrDefault();
                    if (cartitem == null)
                    {
                        //Addto cartitem
                        var item = new CartItem();
                        item.IsActive = true;
                        item.ProductVariantDetailId = pro.CartItems[0].ProductVariantDetailId;
                        item.Quantity       = pro.CartItems[0].Quantity == 0?1:pro.CartItems[0].Quantity;
                        item.UnitId         = 1;
                        item.VendorId       = pro.CartItems[0].VendorId;
                        item.CartId         = model.Id;
                        item.ShipmentVendor = pro.CartItems[0].ShipmentVendor;
                        db.CartItems.Add(item);
                        db.SaveChanges();
                        //TotalAmount withCommission in cart
                        //var cartdata = db.Carts.Where(x => x.Id == model.Id).FirstOrDefault();
                        //cartdata.TotalAmount = item.Amount;
                        //db.SaveChanges();
                    }
                    else
                    {
                        var now      = pro.CartItems[0].Quantity == 0 ? 1 : pro.CartItems[0].Quantity;
                        var quantity = cartitem.Quantity + now;
                        cartitem.Quantity = quantity;
                        //var pricewithcommission = cartitem.UnitPrice + cartitem.Commission;
                        //var discountedPrice = pricewithcommission - (pricewithcommission * cartitem.Discount / 100);
                        //cartitem.Amount = discountedPrice * quantity;
                        db.Entry(cartitem).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    //cart.TotalAmount = db.CartItems.Where(x => x.CartId == cart.Id && x.IsActive == true).AsNoTracking().ToList().Sum(x => x.Amount);
                    cart.IpAddress       = model.IpAddress;
                    cart.OrderDate       = DateTime.Now;
                    db.Entry(cart).State = EntityState.Modified;
                    db.SaveChanges();
                }

                return(Ok(pro.CartItems[0].ShipmentVendor ?? false));
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                return(Ok());
            }
        }
Пример #7
0
        public async Task <IActionResult> addSlider([FromBody] Slider model)
        {
            JsonResult response = null;

            try
            {
                //----uploaded to s3
                if (model.Image.Contains("https://pistis.s3.us-east-2.amazonaws.com/"))
                {
                    Slider slider = new Slider();
                    slider.FromDateTime = model.FromDateTime;
                    slider.ToDateTime   = model.ToDateTime;
                    slider.IsActive     = true;
                    slider.Url          = model.Url;
                    slider.Image        = model.Image;
                    if (model.Id > 0)
                    {
                        var sliderUpdate = db.Sliders.Where(x => x.Id == model.Id).FirstOrDefault();
                        sliderUpdate.FromDateTime = model.FromDateTime;
                        sliderUpdate.ToDateTime   = model.ToDateTime;
                        slider.Image          = model.Image;
                        sliderUpdate.IsActive = true;
                        sliderUpdate.Url      = model.Url;
                        db.SaveChanges();
                    }
                    else
                    {
                        db.Sliders.Add(slider);
                        db.SaveChanges();
                    }
                }
                else
                {
                    if (model.Image != null)
                    {
                        var imageResponse = await S3Service.UploadObject(model.Image);

                        response = new JsonResult(new Object());
                        if (imageResponse.Success)
                        {
                            Slider slider = new Slider();

                            slider.FromDateTime = model.FromDateTime;
                            slider.ToDateTime   = model.ToDateTime;
                            slider.Image        = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";
                            slider.IsActive     = true;
                            slider.Url          = model.Url;
                            if (model.Id > 0)
                            {
                                var sliderUpdate = db.Sliders.Where(x => x.Id == model.Id).FirstOrDefault();
                                sliderUpdate.FromDateTime = model.FromDateTime;
                                sliderUpdate.ToDateTime   = model.ToDateTime;
                                sliderUpdate.Image        = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";
                                sliderUpdate.IsActive     = true;
                                slider.Url = model.Url;
                                db.Entry(sliderUpdate).State = EntityState.Modified;
                                db.SaveChanges();
                            }
                            else
                            {
                                db.Sliders.Add(slider);
                                db.SaveChanges();
                            }

                            response.StatusCode = 0;
                            response.Value      = "Uploaded done!";
                        }
                        else
                        {
                            response.StatusCode = -1;
                            response.Value      = "Upload failed!";
                        }
                    }

                    //return Request.CreateResponse(HttpStatusCode.Created);
                }
                return(Ok(response));
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                //return Request.CreateResponse(HttpStatusCode.ExpectationFailed);
                return(null);
            }
        }