示例#1
0
        public ActionResult Submit(int id, ImexItem[] items, string note, string receipt)
        {
            var action      = id > 0 ? DbAction.Import.Modify : DbAction.Import.Create;
            var message     = "";
            int?recordID    = null;
            int warehouseID = 0;

            if (id > 0 && !EmployeeInfo.IsAdmin(UserID, Employee.ID, Employee.ID, action))
            {
                message = "Bạn không có quyền sử dụng chức năng này";
            }
            else
            {
                message = "Lưu thông tin không thành công";
                if (items != null && items.Length > 0)
                {
                    var warehouses = items.GroupBy(i => i.WarehouseID);
                    foreach (var warehouse in warehouses)
                    {
                        recordID    = SKtimeManagement.Import.Submit(id, UserID, Employee.ID, Employee.BussinessID, warehouse.Key, warehouse.ToArray(), note, receipt);
                        warehouseID = warehouse.Key;
                    }
                    if (recordID.HasValue)
                    {
                        message = "Lưu thông tin thành công";
                    }
                }
                else
                {
                    message = "Không có sản phẩm được chọn";
                }
            }
            if (!recordID.HasValue)
            {
                var model = new Import(Employee.Name,
                                       WarehouseInfo.FindAuthorized(UserID, Employee.ID, Employee.BussinessID, UserID, DbAction.Import.View),
                                       warehouseID, items, note, message)
                {
                    Receipt = receipt
                };
                model.ID = id;
                if (Request.IsAjaxRequest())
                {
                    return(Json(new
                    {
                        html = RenderPartialViewToString(Views.ImportPartial, model)
                    }, JsonRequestBehavior.DenyGet));
                }
                return(View(Views.Import, model));
            }
            else
            {
                if (Request.IsAjaxRequest())
                {
                    return(Json(new
                    {
                        result = true,
                        redirect = Url.Action("Detail", "Import", new { id = recordID.Value })
                    }, JsonRequestBehavior.DenyGet));
                }
                return(RedirectToAction(Views.Detail, new { id = recordID.Value }));
            }
        }