public ActionResult Create(OrderModel model)
        {
            ResponseJson response = new ResponseJson();
              try
              {
            if (!ModelState.IsValid)
            {
              return Json(Globals.SetValidationError(ModelState));
            }
            //response = Validation(response, model);
            //if (response.IsError)
            //{
            //    return Json(response);
            //}
            //ObjectParameter ErrorCode = new ObjectParameter("ErrorCode", 0);
            UpdatedInfoModel updatedInfo = new UpdatedInfoModel() { Comment = "Order Created", Type = 1, UpdatedTime = DateTime.Now, UserId = CurrentUser.Id };
            string login = "";
            using (AppDB db = new AppDB())
            {

              DAL.Order order = new DAL.Order()
              {
            BuyerId = model.BuyerId,
            CodeNumber = "",
            Color = model.Color,
            CreatedBy = CurrentUser.Id,
            DeliveryDate = model.DeliveryDate,
            Description = model.Description,
            Id = Guid.NewGuid(),
            OrderDate = DateTime.Now,
            Size = model.Size,
            Status = 0,
            Style = model.Style,
            TotalQuantity = model.Quantity,
            UpdateInfo = new JavaScriptSerializer().Serialize(updatedInfo)
              };
              db.Orders.Add(order);
              db.SaveChanges();
              //EmailSender.SendToCHWUser(model.Email, login, login, model.Surname, "Sector Executive Officer");

            }

              }
              catch (Exception ex)
              {
            response.IsError = true;
            response.Id = -6;
              }
              return Json(response);
        }
Exemplo n.º 2
0
        public ActionResult Save(string employeeBarCode, string bundleBarCode)
        {
            ResponseJson response = new ResponseJson();
            try
            {
                if (!ModelState.IsValid)
                {
                    return Json(Globals.SetValidationError(ModelState));
                }

                UpdatedInfoModel updatedInfo = new UpdatedInfoModel() { Comment = "Linking Started", Type = 4, UpdatedTime = DateTime.Now, UserId = CurrentUser.Id };
                using (AppDB db = new AppDB())
                {
                    var bundle = db.Bundles.Where(s => s.BarCode == bundleBarCode).SingleOrDefault();
                    var employee = db.Employees.Where(s => s.BarCode == employeeBarCode).SingleOrDefault();
                    if (bundle != null && bundle.Status !=2 && employee != null)
                    {
                        bundle.LinkingStartAt = DateTime.Now;
                        bundle.LinkingBy = employee.Id;
                        bundle.Status = 2;
                        bundle.UpdateInfo += "," + new JavaScriptSerializer().Serialize(updatedInfo);
                        db.SaveChanges();
                    }
                    else if (bundle == null)
                    {
                        response.IsError = true;
                        response.Id = -11;
                    }
                    else if (bundle.Status == 2)
                    {
                        response.IsError = true;
                        response.Id = -12;
                    }
                    else
                    {
                        response.IsError = true;
                        response.Id = -13;
                    }
                }
            }
            catch (Exception ex)
            {
                response.IsError = true;
                response.Id = -6;
            }
            return Json(response);
        }
        public ActionResult Create(SellerModel model)
        {
            ResponseJson response = new ResponseJson();
            try
            {
                if (!ModelState.IsValid)
                {
                    return Json(Globals.SetValidationError(ModelState));
                }
                //response = Validation(response, model);
                //if (response.IsError)
                //{
                //    return Json(response);
                //}
                //ObjectParameter ErrorCode = new ObjectParameter("ErrorCode", 0);
                UpdatedInfoModel updatedInfo = new UpdatedInfoModel() { Comment = "Seller Created", Type = 1, UpdatedTime = DateTime.Now, UserId = CurrentUser.Id };

                using (AppDB db = new AppDB())
                {

                    DAL.Seller seller = new DAL.Seller()
                    {
                        CreatedBy = CurrentUser.Id,
                        Description = model.Description,
                        Id = Guid.NewGuid(),
                        Name=model.Name,
                        CreatedAt = DateTime.Now,
                        Phone = model.Phone,
                        Email = model.Email,
                        Address = model.Address,
                        UpdateInfo = new JavaScriptSerializer().Serialize(updatedInfo)
                    };
                    db.Sellers.Add(seller);
                    db.SaveChanges();
                    response.Data = new { Id = seller.Id, Name = seller.Name };
                    //EmailSender.SendToCHWUser(model.Email, login, login, model.Surname, "Sector Executive Officer");

                }

            }
            catch (Exception ex)
            {
                response.IsError = true;
                response.Id = -6;
            }
            return Json(response);
        }
        public ActionResult Create(StyleModel model)
        {
            ResponseJson response = new ResponseJson();
            try
            {
                if (!ModelState.IsValid)
                {
                    return Json(Globals.SetValidationError(ModelState));
                }
                //response = Validation(response, model);
                //if (response.IsError)
                //{
                //    return Json(response);
                //}
                //ObjectParameter ErrorCode = new ObjectParameter("ErrorCode", 0);
                UpdatedInfoModel updatedInfo = new UpdatedInfoModel() { Comment = "Style Created", Type = 1, UpdatedTime = DateTime.Now, UserId = CurrentUser.Id };
                using (AppDB db = new AppDB())
                {
                    DAL.Style style = new DAL.Style()
                    {
                        Id=Guid.NewGuid(),
                        BuyerId = model.BuyerId,
                        BarCode = Globals.GetBarCode(),
                        Name = model.Name,
                        CreatedBy = CurrentUser.Id,
                        YarnType = model.YarnType,
                        Size = model.Size,
                        Description = model.Description,
                        ShippingDate = model.ShippingDate,
                        Status = 0,
                        CreatedAt = DateTime.Now,
                        Quantity = model.Quantity,
                        UpdateInfo = new JavaScriptSerializer().Serialize(updatedInfo)
                    };
                    db.Styles.Add(style);
                    db.SaveChanges();
                    //EmailSender.SendToCHWUser(model.Email, login, login, model.Surname, "Sector Executive Officer");
                }

            }
            catch (Exception ex)
            {
                response.IsError = true;
                response.Id = -6;
            }
            return Json(response);
        }
        public ActionResult Save(string bundleBarCode)
        {
            ResponseJson response = new ResponseJson();
            try
            {
                if (!ModelState.IsValid)
                {
                    return Json(Globals.SetValidationError(ModelState));
                }

                UpdatedInfoModel updatedInfo = new UpdatedInfoModel() { Comment = "Linking Ended", Type = 5, UpdatedTime = DateTime.Now, UserId = CurrentUser.Id };
                using (AppDB db = new AppDB())
                {
                    var bundle = db.Bundles.Where(s => s.BarCode == bundleBarCode).SingleOrDefault();
                    if (bundle != null && bundle.Status==2)
                    {
                        bundle.LinkingEndAt = DateTime.Now;
                        //bundle.LinkingEndAt = employee.Id;
                        bundle.UpdateInfo += "," + new JavaScriptSerializer().Serialize(updatedInfo);
                        bundle.Status = 3;
                        db.SaveChanges();
                    } else if (bundle == null)
                    {
                        response.IsError = true;
                        response.Id = -11;
                    }
                    else if (bundle.Status != 2)
                    {
                        response.IsError = true;
                        response.Id = -12;
                    } else
                    {
                        response.IsError = true;
                        response.Id = -13;
                    }
                    //EmailSender.SendToCHWUser(model.Email, login, login, model.Surname, "Sector Executive Officer");
                }

            }
            catch (Exception ex)
            {
                response.IsError = true;
                response.Id = -6;
            }
            return Json(response);
        }
        public ActionResult Create(EmployeeModel model)
        {
            ResponseJson response = new ResponseJson();
              try
              {
            if (!ModelState.IsValid)
            {
              return Json(Globals.SetValidationError(ModelState));
            }

            UpdatedInfoModel updatedInfo = new UpdatedInfoModel() { Comment = "Employee Created", Type = 1, UpdatedTime = DateTime.Now, UserId = CurrentUser.Id };
            using (AppDB db = new AppDB())
            {
              DAL.Employee bundle = new DAL.Employee()
              {
            Id = Guid.NewGuid(),
            Name = model.Name,
            BarCode = Globals.GetBarCode(),
            CreatedBy = CurrentUser.Id,
            UserName = model.UserName,
            Password = Globals.Encrypt(model.Password),
            Phone = model.Phone,
            Email = model.Email,
            IsActive = true,
            Address = model.Address,
            Role = model.Role,
            CreatedAt = DateTime.Now,
            UpdateInfo = new JavaScriptSerializer().Serialize(updatedInfo)
              };
              db.Employees.Add(bundle);
              db.SaveChanges();
              //EmailSender.SendToCHWUser(model.Email, login, login, model.Surname, "Sector Executive Officer");
            }

              }
              catch (Exception ex)
              {
            response.IsError = true;
            response.Id = -6;
              }
              return Json(response);
        }
        public ActionResult Create(MaterialModel model)
        {
            ResponseJson response = new ResponseJson();
            try
            {
                if (!ModelState.IsValid)
                {
                    return Json(Globals.SetValidationError(ModelState));
                }

                UpdatedInfoModel updatedInfo = new UpdatedInfoModel() { Comment = "Material Created", Type = 1, UpdatedTime = DateTime.Now, UserId = CurrentUser.Id };

                using (AppDB db = new AppDB())
                {

                    DAL.Material seller = new DAL.Material()
                    {
                        SellerId=model.SellerId,
                        OrderId=model.OrderId,
                        Amount=model.Amount,
                        OrderDate=DateTime.Now,
                        DeliveryDate=model.DeliveryDate,
                        CreatedBy = CurrentUser.Id,
                        Description = model.Description,
                        Id = Guid.NewGuid(),
                        CreatedAt = DateTime.Now,
                        UpdateInfo = new JavaScriptSerializer().Serialize(updatedInfo)
                    };
                    db.Materials.Add(seller);
                    db.SaveChanges();
                }

            }
            catch (Exception ex)
            {
                response.IsError = true;
                response.Id = -6;
            }
            return Json(response);
        }
        public ActionResult Create(BundleModel model)
        {
            ResponseJson response = new ResponseJson();
            try
            {
                if (!ModelState.IsValid)
                {
                    return Json(Globals.SetValidationError(ModelState));
                }

                UpdatedInfoModel updatedInfo = new UpdatedInfoModel() { Comment = "Bundle Created", Type = 1, UpdatedTime = DateTime.Now, UserId = CurrentUser.Id };
                using (AppDB db = new AppDB())
                {
                    DAL.Bundle bundle = new DAL.Bundle()
                    {
                        Id = Guid.NewGuid(),
                        StyleId = model.StyleId,
                        BarCode = Globals.GetBarCode(),
                        CreatedBy = CurrentUser.Id,
                        KnittingMachine = model.KnittingMachine,
                        OperatorId = model.OperatorId,
                        Status = 0,
                        CreatedAt = DateTime.Now,
                        Quantity = model.Quantity,
                        UpdateInfo = new JavaScriptSerializer().Serialize(updatedInfo)
                    };
                    db.Bundles.Add(bundle);
                    db.SaveChanges();
                    //EmailSender.SendToCHWUser(model.Email, login, login, model.Surname, "Sector Executive Officer");
                }

            }
            catch (Exception ex)
            {
                response.IsError = true;
                response.Id = -6;
            }
            return Json(response);
        }
        public ActionResult SaveChange(EmployeeModel model)
        {
            ResponseJson response = new ResponseJson();
              try
              {
            if (!ModelState.IsValid)
            {
              return Json(Globals.SetValidationError(ModelState));
            }

            UpdatedInfoModel updatedInfo = new UpdatedInfoModel() { Comment = "Update Employee", Type = 2, UpdatedTime = DateTime.Now, UserId = CurrentUser.Id };
            using (AppDB db = new AppDB())
            {
              var bundle = db.Employees.Where(s => s.Id == model.Id).SingleOrDefault();

              if (bundle != null)
              {
            bundle.Name = model.Name;
            bundle.Phone = model.Phone;
            bundle.Email = model.Email;
            bundle.Address = model.Address;
            bundle.Role = model.Role;
            bundle.UpdateInfo += "," + new JavaScriptSerializer().Serialize(updatedInfo);
            db.SaveChanges();
              }
              else
              {
            response.IsError = true;
            response.Id = -3;
              }
              //EmailSender.SendToCHWUser(model.Email, login, login, model.Surname, "Sector Executive Officer");
            }

              }
              catch (Exception ex)
              {
            response.IsError = true;
            response.Id = -6;
              }
              return Json(response);
        }
        public ActionResult SaveChange(StyleModel model)
        {
            ResponseJson response = new ResponseJson();
            try
            {
                if (!ModelState.IsValid)
                {
                    return Json(Globals.SetValidationError(ModelState));
                }

                UpdatedInfoModel updatedInfo = new UpdatedInfoModel() { Comment = "Update Style", Type = 2, UpdatedTime = DateTime.Now, UserId = CurrentUser.Id };
                using (AppDB db = new AppDB())
                {
                    var style = db.Styles.Where(s => s.Id == model.Id).SingleOrDefault();

                    if (style != null)
                    {
                        style.BuyerId = model.BuyerId;
                        style.Name = model.Name;
                        style.YarnType = model.YarnType;
                        style.Size = model.Size;
                        style.Description = model.Description;
                        style.ShippingDate = model.ShippingDate;
                        style.Quantity = model.Quantity;
                        style.UpdateInfo += "," + new JavaScriptSerializer().Serialize(updatedInfo);

                        //db.Styles.Add(style);
                        db.SaveChanges();
                    }
                    else
                    {
                        response.IsError = true;
                        response.Id = -3;
                    }
                    //EmailSender.SendToCHWUser(model.Email, login, login, model.Surname, "Sector Executive Officer");
                }

            }
            catch (Exception ex)
            {
                response.IsError = true;
                response.Id = -6;
            }
            return Json(response);
        }