示例#1
0
        public async Task <ActionResult> UpdateAcount(CustomerAppIG4Item data)
        {
            var customer = _agencyDa.GetById(CustomerId);

            if (customer == null)
            {
                return(Json(new JsonMessage(1000, "Not found")));
            }

            if (!string.IsNullOrEmpty(data.Mobile) && customerDA.CheckExitsByPhone(CustomerId, data.Mobile))
            {
                return(Json(new JsonMessage(1000, "Số điện thoại đã tồn tại")));
            }

            if (!string.IsNullOrEmpty(data.Email) && customerDA.CheckExitsByEmail(CustomerId, data.Email))
            {
                return(Json(new JsonMessage(1000, "Email đã tồn tại")));
            }
            customer.Email = data.Email;
            //customer.Description = data.Description;
            customer.FullName = data.Fullname;
            customer.Address  = data.Address;
            //customer.Mobile = data.Mobile;

            var file = Request.Files["fileAvatar"];

            if (file != null)
            {
                var img = await UploadImage(file);

                if (img.Code != 200)
                {
                    return(Json(new JsonMessage(1000, "Tải Avatar không thành công")));
                }
                customer.AvatarUrl = img.Data.Folder + img.Data.Url;
            }
            file = Request.Files["fileImgTimeline"];
            if (file != null)
            {
                var img = await UploadImage(file);

                if (img.Code != 200)
                {
                    return(Json(new JsonMessage(1000, "Tải ảnh bìa không thành công")));
                }
                customer.ImageTimeline = img.Data.Folder + img.Data.Url;
            }
            customerDA.Save();
            var obj = _agencyDa.GetItemByIdApp(CustomerId);

            return(Json(new BaseResponse <CustomerAppIG4Item> {
                Code = 200, Data = obj
            }, JsonRequestBehavior.AllowGet));
        }
示例#2
0
 public ActionResult UpdateUser(string key, string username, int gender, string address, string birthday,
                                string fullname, string pass, string company, string depart, string mst, string stk, string bankname, string latitute, string longitude)
 {
     if (key != Keyapi)
     {
         return(Json(0, JsonRequestBehavior.AllowGet));
     }
     try
     {
         var model = _da.GetByUsername(username);
         if (model != null)
         {
             model.Address         = address;
             model.Gender          = gender == 1;
             model.BirthDay        = ConvertUtil.ToDateTime(birthday).TotalSeconds();
             model.LoweredUserName = fullname;
             if (!string.IsNullOrEmpty(pass))
             {
                 var saltKey          = FDIUtils.CreateSaltKey(5);
                 var sha1PasswordHash = FDIUtils.CreatePasswordHash(pass, saltKey);
                 model.Password = sha1PasswordHash;
             }
             var agency = _agencyDa.GetById(model.AgencyID ?? 0);
             agency.Company    = company;
             agency.MST        = mst;
             agency.Department = depart;
             agency.STK        = stk;
             agency.BankName   = bankname;
             agency.Latitute   = latitute;
             agency.Longitude  = longitude;
             _agencyDa.Save();
             _da.Save();
             return(Json(1, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception e)
     {
         return(Json(e.Message, JsonRequestBehavior.AllowGet));
     }
     return(Json(3, JsonRequestBehavior.AllowGet));
 }
示例#3
0
        public ActionResult Update(string key, string json)
        {
            var msg = new JsonMessage(false, "Cập nhật dữ liệu thành công.");

            try
            {
                if (key == Keyapi)
                {
                    var objitem = JsonConvert.DeserializeObject <AgencyItem>(json);
                    var obj     = _da.GetById(objitem.ID);
                    var check   = obj.GroupID != objitem.GroupID;
                    if (obj.GroupID > 0 && check)
                    {
                        _da.InsertDNModule(objitem.GroupID, obj.ID, true);
                    }

                    obj = UpdateBase(obj, objitem);
                    _da.Save();
                    if (!string.IsNullOrEmpty(objitem.Pass))
                    {
                        var user = _daUserDa.GetUserByUserName(objitem.UserName);
                        if (user != null)
                        {
                            var sha1PasswordHash = FDIUtils.CreatePasswordHash(objitem.Pass, user.PasswordSalt);
                            user.Password = sha1PasswordHash;
                        }
                        else
                        {
                            var date = ConvertDate.TotalSeconds(DateTime.Now);
                            var role = _darRoleDa.GetByName("Admin");
                            if (role == null)
                            {
                                role = new DN_Roles {
                                    RoleId = Guid.NewGuid(), RoleName = "Admin", LoweredRoleName = "admin", AgencyID = obj.ID, Description = "Quản trị"
                                };
                                _darRoleDa.Add(role);
                                _darRoleDa.Save();
                            }
                            var saltKey          = FDIUtils.CreateSaltKey(5);
                            var sha1PasswordHash = FDIUtils.CreatePasswordHash(objitem.Pass, saltKey);
                            user = new DN_Users
                            {
                                UserId          = Guid.NewGuid(),
                                PasswordSalt    = saltKey,
                                Password        = sha1PasswordHash,
                                UserName        = objitem.UserName,
                                LoweredUserName = obj.Name,
                                Email           = obj.Email,
                                Address         = obj.Address,
                                AgencyID        = obj.ID,
                                Mobile          = obj.Phone,
                                IsApproved      = true,
                                IsLockedOut     = false,
                                CreateDate      = date,
                                IsDeleted       = false
                            };
                            _daUserDa.Add(user);
                            var dnUsersInRoles = new DN_UsersInRoles
                            {
                                UserId      = role.RoleId,
                                AgencyID    = obj.ID,
                                DateCreated = date
                            };
                            user.DN_UsersInRoles.Add(dnUsersInRoles);
                        }
                        _daUserDa.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                msg.Erros   = true;
                msg.Message = "Dữ liệu chưa được cập nhật.";
                Log2File.LogExceptionToFile(ex);
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
示例#4
0
        public ActionResult CreateOder(int id, Guid keyGuid)
        {
            var lstOrder = (List <ModelWholeSaleItem>)Session["WholeSale"] ?? new List <ModelWholeSaleItem>();

            if (lstOrder.Any())
            {
                var temp = _da.GetById(id);
                if (keyGuid == temp.keyreq)
                {
                    var models = lstOrder.Where(c => c.Key == keyGuid);
                    if (!models.Any())
                    {
                        var lst   = temp.FreightWareHouse_Active;
                        var model = new ModelWholeSaleItem {
                            Key = keyGuid
                        };
                        var lsttemp = new List <WholeSaleItem>();
                        foreach (var item in lst)
                        {
                            var saleProducts = _dnSalesDa.GetSaleProduct(item.ProductID ?? 0, UserItem.AgencyID);
                            var pricesale    = saleProducts.Sale.Any() ? saleProducts.Sale.Sum(c => c.Price) : 0;
                            var percent      = saleProducts.Sale.Any() ? saleProducts.Sale.Sum(c => c.PercentSale) : 0;
                            var discount     = pricesale + (item.Price * percent / 100);
                            // var checkpromotion = _dnPromotionDa.GetPromotionProduct(item.ProductID ?? 0, UserItem.AgencyID, item.QuantityActive ?? 1);
                            var urlimg = "/Content/Admin/images/auto-default.jpg";
                            if (item.Shop_Product.Shop_Product_Detail.Gallery_Picture != null)
                            {
                                urlimg = "/Uploads/" + item.Shop_Product.Shop_Product_Detail.Gallery_Picture.Folder +
                                         item.Shop_Product.Shop_Product_Detail.Gallery_Picture.Url;
                            }

                            var a = new WholeSaleItem
                            {
                                Key             = CodeLogin(),
                                PriceSale       = pricesale,
                                PercentSale     = percent,
                                Value           = item.ValueWeight,
                                Discount        = discount,
                                TotalPrice      = (item.Shop_Product.Shop_Product_Detail.Price * (decimal)item.Shop_Product.Product_Size.Value / 1000 * item.Quantity * item.ValueWeight) - discount,
                                Quantity        = item.Quantity,
                                Barcode         = item.BarCode,
                                Price           = item.Shop_Product.Shop_Product_Detail.Price * (decimal)item.Shop_Product.Product_Size.Value / 1000,
                                Code            = item.Shop_Product.CodeSku,
                                ProductID       = item.ProductID ?? 0,
                                Idimport        = item.ImportProductGID,
                                ProductdetailID = item.Shop_Product.Shop_Product_Detail.ID,
                                Title           = item.Shop_Product.Shop_Product_Detail.Name,
                                UrlImg          = urlimg
                            };
                            lsttemp.Add(a);
                        }
                        model.WholeSaleItems = lsttemp;
                        var total = model.WholeSaleItems.Sum(c => c.TotalPrice * c.Quantity);
                        var sale  = _dnSalesDa.GetSaleByTotalOrder((decimal)total, UserItem.AgencyID);
                        model.SaleOrder = sale;
                        var checkdiscount = _dnAgencyDa.GetById(temp.AgencyId ?? 0);
                        var agency        = new AgentSaleItem
                        {
                            Address = checkdiscount.Address,
                            Name    = checkdiscount.Name,
                            Phone   = checkdiscount.Phone,
                            //Bonus = checkdiscount.
                            ID         = checkdiscount.ID,
                            AgentGroup = checkdiscount.DN_GroupAgency.Name
                        };
                        model.AgentSaleItem = agency;
                        var discsl = ((total * sale.Sum(p => p.PercentSale) / 100) + sale.Sum(p => p.Price));
                        var disc   = (total * (checkdiscount.DN_GroupAgency.Discount ?? 0) / 100);
                        model.DiscountSale = discsl;
                        model.Discount     = disc;
                        model.SalePercent  = total * sale.Sum(p => p.PercentSale) / 100;
                        model.SalePrice    = sale.Sum(p => p.Price);
                        model.Total        = total;
                        model.TotalPrice   = total - discsl - disc;
                        lstOrder.Add(model);
                        Session["WholeSale"] = lstOrder;
                    }
                }
            }
            else
            {
                var temp = _da.GetById(id);
                if (keyGuid == temp.keyreq)
                {
                    var lst   = temp.FreightWareHouse_Active;
                    var model = new ModelWholeSaleItem {
                        Key = keyGuid
                    };
                    var lsttemp = new List <WholeSaleItem>();
                    foreach (var item in lst)
                    {
                        var saleProducts = _dnSalesDa.GetSaleProduct(item.ProductID ?? 0, UserItem.AgencyID);
                        var pricesale    = saleProducts.Sale.Any() ? saleProducts.Sale.Sum(c => c.Price) : 0;
                        var percent      = saleProducts.Sale.Any() ? saleProducts.Sale.Sum(c => c.PercentSale) : 0;
                        var discount     = pricesale + (item.Price * percent / 100);
                        // var checkpromotion = _dnPromotionDa.GetPromotionProduct(item.ProductID ?? 0, UserItem.AgencyID, item.QuantityActive ?? 1);
                        var urlimg = "/Content/Admin/images/auto-default.jpg";
                        if (item.Shop_Product.Shop_Product_Detail.Gallery_Picture != null)
                        {
                            urlimg = "/Uploads/" + item.Shop_Product.Shop_Product_Detail.Gallery_Picture.Folder +
                                     item.Shop_Product.Shop_Product_Detail.Gallery_Picture.Url;
                        }

                        var a = new WholeSaleItem
                        {
                            Key             = CodeLogin(),
                            PriceSale       = pricesale,
                            PercentSale     = percent,
                            Value           = item.ValueWeight,
                            Idimport        = item.ImportProductGID,
                            Discount        = discount,
                            TotalPrice      = (item.Shop_Product.Shop_Product_Detail.Price * (decimal)item.Shop_Product.Product_Size.Value / 1000 * item.Quantity * item.ValueWeight) - discount,
                            Quantity        = item.Quantity,
                            Price           = item.Shop_Product.Shop_Product_Detail.Price * (decimal)item.Shop_Product.Product_Size.Value / 1000,
                            Code            = item.Shop_Product.CodeSku,
                            Barcode         = item.BarCode,
                            ProductID       = item.ProductID ?? 0,
                            ProductdetailID = item.Shop_Product.Shop_Product_Detail.ID,
                            Title           = item.Shop_Product.Shop_Product_Detail.Name,
                            UrlImg          = urlimg
                        };
                        lsttemp.Add(a);
                    }
                    model.WholeSaleItems = lsttemp;
                    var total = model.WholeSaleItems.Sum(c => c.TotalPrice);
                    var sale  = _dnSalesDa.GetSaleByTotalOrder((decimal)total, UserItem.AgencyID);
                    model.SaleOrder = sale;
                    var checkdiscount = _dnAgencyDa.GetById(temp.AgencyId ?? 0);
                    var agency        = new AgentSaleItem
                    {
                        Address = checkdiscount.Address,
                        Name    = checkdiscount.Name,
                        Phone   = checkdiscount.Phone,
                        //Bonus = checkdiscount.
                        ID         = checkdiscount.ID,
                        AgentGroup = checkdiscount.DN_GroupAgency.Name
                    };
                    model.AgentSaleItem = agency;
                    var discsl = ((total * sale.Sum(p => p.PercentSale) / 100) + sale.Sum(p => p.Price));
                    var disc   = (total * (checkdiscount.DN_GroupAgency.Discount ?? 0) / 100);
                    model.DiscountSale = discsl;
                    model.Discount     = disc;
                    model.Total        = total;
                    model.TotalPrice   = total - discsl - disc;
                    lstOrder.Add(model);
                    Session["WholeSale"] = lstOrder;
                }
            }

            return(RedirectToAction("Index", "WholeSale"));
        }