Ejemplo n.º 1
0
        public ActionResult UpdateProductType(string orderId, string productId, string type)
        {
            var orderProduct = db.OrderProducts.Where(p => p.ProductId == productId && p.OrderId == orderId).FirstOrDefault();

            if (orderProduct == null)
            {
                return(Json(new { id = 0 }, JsonRequestBehavior.AllowGet));
            }

            orderProduct.ProductType = type;

            db.Entry(orderProduct).State = EntityState.Modified;
            db.SaveChanges();

            string typeName = "Chưa xác định";

            if (type == "warehouse")
            {
                typeName = "Hàng gửi kho";
            }
            else if (type == "new")
            {
                typeName = "Hàng xuất mới";
            }

            var staff = orderProduct.HaiOrder.OrderStaffs.Where(p => p.ProcessId == "create").FirstOrDefault();

            if (staff != null)
            {
                Utitl.Send("Đơn hàng " + orderProduct.HaiOrder.Code, "Đã thay đổi loại hàng: " + typeName, staff.HaiStaff.UserLogin, db, mongoHelp);
            }


            return(Json(new { id = 1 }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult ResetImei(string user)
        {
            if (!Utitl.CheckUser(db, User.Identity.Name, "CheckImei", 0))
            {
                return(RedirectToAction("relogin", "home"));
            }

            var data = db.ImeiUsers.Where(p => p.UserName == user).FirstOrDefault();

            if (data != null)
            {
                data.IsUpdate        = 1;
                db.Entry(data).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            return(RedirectToAction("CheckImei", "UserImei", new { user = user }));
        }
Ejemplo n.º 3
0
        public ActionResult ApproveCalendar(string id, string notes)
        {
            if (!Utitl.CheckUser(db, User.Identity.Name, "CheckIn", 0))
            {
                return(RedirectToAction("relogin", "home"));
            }
            var calendar = db.CalendarInfoes.Find(id);

            if (calendar != null)
            {
                calendar.Notes           = notes;
                calendar.CStatus         = 1;
                db.Entry(calendar).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            return(RedirectToAction("showcalendardetail", "checkin", new { id = id }));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> RegisterStaff(RegisterViewModel model, string StaffId, string role)
        {
            if (ModelState.IsValid)
            {
                var check = db.HaiStaffs.Find(StaffId);

                if (check == null)
                {
                    return(RedirectToAction("error", "home"));
                }

                var user = new ApplicationUser()
                {
                    UserName    = model.UserName,
                    IsActivced  = 1,
                    FullName    = check.FullName,
                    AccountType = "STAFF"
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    check.UserLogin       = user.UserName;
                    db.Entry(check).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    result = UserManager.AddToRole(user.Id, role);

                    RedirectToAction("modifystaff", "haistaff", new { Id = StaffId });
                }
                else
                {
                    AddErrors(result);
                }
            }
            // If we got this far, something failed, redisplay form
            return(RedirectToAction("modifystaff", "haistaff", new { Id = StaffId, model }));
        }
Ejemplo n.º 5
0
        public ActionResult CreateStaff(HaiStaff staff, string birthday, HttpPostedFileBase avatar, HttpPostedFileBase signature)
        {
            if (!Utitl.CheckUser(db, User.Identity.Name, "ManageStaff", 1))
            {
                return(RedirectToAction("relogin", "home"));
            }

            staff.CreateDate = DateTime.Now;
            staff.IsLock     = 0;

            try
            {
                DateTime dt           = DateTime.ParseExact(birthday, "MM/dd/yyyy HH:mm", null);
                string   urlAvatar    = UploadImage(avatar, "/staff/avatar", ".jpg", staff.Code);
                string   urlSignature = UploadImage(signature, "/staff/signature", ".png", staff.Code);

                staff.AvatarUrl    = urlAvatar;
                staff.SignatureUrl = urlSignature;
                staff.Id           = Guid.NewGuid().ToString();
                staff.IsLock       = 0;
                staff.Code         = generalCode();

                db.HaiStaffs.Add(staff);
                db.SaveChanges();

                var findStoreId = db.StoreStaffIds.Find(staff.Code);
                findStoreId.IsUser          = 1;
                db.Entry(findStoreId).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            catch
            {
            }

            return(RedirectToAction("modifystaff", "haistaff", new { id = staff.Id }));
        }
Ejemplo n.º 6
0
        public ActionResult AddFuncIsAll(int FuncId, String RoleName, bool isAdd)
        {
            var func = db.FuncInfoes.Find(FuncId);

            if (func == null)
            {
                return(Content("Chức năng sai."));
            }

            var role = db.AspNetRoles.Where(p => p.Name == RoleName).FirstOrDefault();

            if (role == null)
            {
                return(Content("Quyền sai."));
            }

            var funcRole = db.FuncRoles.Where(p => p.FuncId == func.Id && p.RoleId == role.Id).FirstOrDefault();

            if (funcRole == null)
            {
                return(Content("Chua thêm chức năng này."));
            }

            if (isAdd)
            {
                funcRole.IsAll = 1;
            }
            else
            {
                funcRole.IsAll = 0;
            }

            db.Entry(funcRole).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            return(Content("Đã sét toàn quyền."));
        }
Ejemplo n.º 7
0
        public MainInfoResult MainInfo()
        {
            // update regid firebase
            // /api/rest/getmaininfo
            var history = new MongoHistoryAPI()
            {
                CreateTime = DateTime.Now,
                APIUrl     = "/api/restmain/maininfo",
                Sucess     = 1
            };

            var result = new MainInfoResult()
            {
                id = "1"
            };

            var requestContent = Request.Content.ReadAsStringAsync().Result;

            history.Content = requestContent;

            try
            {
                var jsonserializer = new JavaScriptSerializer();
                var paser          = jsonserializer.Deserialize <MainInfoRequest>(requestContent);
                history.Content = new JavaScriptSerializer().Serialize(paser);

                // if (!mongoHelper.checkLoginSession(paser.user, paser.token))
                //  throw new Exception("Tài khoản bạn đã đăng nhập ở thiết bị khác.");

                var checkUser = db.AspNetUsers.Where(p => p.UserName == paser.user).FirstOrDefault();

                if (checkUser == null)
                {
                    throw new Exception("Lỗi");
                }

                var role = checkUser.AspNetRoles.FirstOrDefault();

                // get topic
                result.topics = GetUserTopics(paser.user);

                result.function = GetUserFunction(paser.user, "main");


                if (role.GroupRole == "HAI")
                {
                    var staff = db.HaiStaffs.Where(p => p.UserLogin == paser.user).FirstOrDefault();
                    if (staff == null)
                    {
                        throw new Exception("Không lấy được thông tin");
                    }

                    result.code = staff.Code;
                    result.name = staff.FullName;
                    result.type = "Công ty HAI";

                    /*
                     * if (paser.isUpdate == 1)
                     * {
                     *  result.c2 = GetListC2(staff);
                     *
                     *  result.c1 = GetListC1(staff);
                     *
                     *  if (paser.isUpdate == 1)
                     *  {
                     *      result.products = GetProductCodeInfo();
                     *      result.productGroups = GetGroupProduct();
                     *  }
                     * }
                     */
                }
                else
                {
                    var cinfo = db.CInfoCommons.Where(p => p.UserLogin == paser.user).FirstOrDefault();

                    if (cinfo == null)
                    {
                        throw new Exception("Không lấy được thông tin");
                    }


                    result.code = cinfo.CCode;
                    result.name = cinfo.CDeputy;
                    if (cinfo.CType == "CII")
                    {
                        result.type = "Đại lý cấp 2";
                    }
                    else if (cinfo.CType == "CI")
                    {
                        result.type = "Đại lý cấp 1";
                    }
                    else
                    {
                        result.type = "Chưa xác nhận";
                    }

                    //  result.c2 = new List<AgencyInfoC2>();
                    //  result.c1 = new List<AgencyInfo>();
                }


                var notiReg = db.RegFirebases.Where(p => p.UserLogin == paser.user).FirstOrDefault();

                if (notiReg == null)
                {
                    notiReg = new RegFirebase()
                    {
                        Id         = Guid.NewGuid().ToString(),
                        UserLogin  = paser.user,
                        RegId      = paser.regId,
                        CreateDate = DateTime.Now
                    };

                    db.RegFirebases.Add(notiReg);
                    db.SaveChanges();
                }
                else
                {
                    notiReg.RegId           = paser.regId;
                    notiReg.ModifyDate      = DateTime.Now;
                    db.Entry(notiReg).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result.id      = "0";
                result.msg     = e.Message;
                history.Sucess = 0;
            }

            history.ReturnInfo = new JavaScriptSerializer().Serialize(result);

            mongoHelper.createHistoryAPI(history);

            return(result);
        }
Ejemplo n.º 8
0
        private SMSResult checkContent(SMSContent paser)
        {
            var result = new SMSResult()
            {
                status = 1
            };

            try
            {
                var c2 = db.C2Info.Where(p => p.Code == paser.code).FirstOrDefault();

                if (c2 == null)
                {
                    return new SMSResult {
                               status = 1, message = "Ma khach hang vua nhan tin khong ton tai trong he thong. Chi tiet lien he NVTT hoac 1800577768"
                    }
                }
                ;


                if (c2.CInfoCommon.Phone != paser.phone)
                {
                    return(new SMSResult {
                        status = 1, message = "So dien thoai Quy Khach vua nhan tin chua dang ky tham gia Chuong trinh nhan tin cung voi Cong ty HAI. Chi tiet lien he NVTT hoac 1800577768"
                    });
                }

                var cInfo = c2.CInfoCommon;

                // lay danh sach sự kiện phù hợp với user (theo khu vực)
                List <EventInfo> listEventUser = new List <EventInfo>();

                //  var eventArea = db.EventAreas.Where(p => p.AreaId == cInfo.AreaId && p.EventInfo.ESTT == 1).ToList();
                var dateNow   = DateTime.Now;
                var eventArea = (from log in db.EventAreas
                                 where log.AreaId == cInfo.AreaId && log.EventInfo.ESTT == 1 && (DbFunctions.TruncateTime(log.EventInfo.BeginTime)
                                                                                                 <= DbFunctions.TruncateTime(dateNow) && DbFunctions.TruncateTime(log.EventInfo.EndTime)
                                                                                                 >= DbFunctions.TruncateTime(dateNow))
                                 select log).ToList();

                foreach (var item in eventArea)
                {
                    var cusJoin = db.EventCustomers.Where(p => p.EventId == item.EventId && p.CInfoCommon.AreaId == item.AreaId).ToList();

                    if (cusJoin.Count() > 0)
                    {
                        var cJoin = cusJoin.Where(p => p.CInfoId == cInfo.Id).FirstOrDefault();
                        if (cJoin != null)
                        {
                            listEventUser.Add(item.EventInfo);
                        }
                    }
                    else
                    {
                        listEventUser.Add(item.EventInfo);
                    }
                }

                if (listEventUser.Count() == 0)
                {
                    return new SMSResult {
                               status = 1, message = "Hien tai Cong ty HAI chua co Chuong trinh khuyen mai. Quy khach vui long theo doi tin nhan SMS hoac tin thong bao trong ung dung CSKH HAI. Xin cam on"
                    }
                }
                ;


                // kiem tra ma dung, ma sau
                List <ProductSeri> righCode = new List <ProductSeri>();

                foreach (var item in paser.products)
                {
                    // lây mã seri // eventCode or seri
                    var productSeri = db.ProductSeris.Where(p => p.Code == item && p.SeriType == 1).FirstOrDefault();

                    if (productSeri == null)
                    {
                        return(new SMSResult {
                            status = 4, message = "Ma " + item + " khong dung. Vui long kiem tra lai ma so nhan tin. Xin cam on"
                        });
                    }
                    else if (productSeri.IsUse == 1)
                    {
                        return(new SMSResult {
                            status = 4, message = "Ma " + item + " da duoc su dung vao (" + productSeri.ModifyTime + "), Vui long kiem tra lai ma so nhan tin. Xin cam on"
                        });
                    }
                    else
                    {
                        righCode.Add(productSeri);
                    }
                }

                Hashtable map = new Hashtable();

                List <string> productAttend = new List <string>();

                result.status = 5;

                foreach (var item in righCode)
                {
                    try
                    {
                        // cap nhat lịch su
                        var hEvent = new MSGPoint()
                        {
                            Id         = Guid.NewGuid().ToString(),
                            AcceptTime = DateTime.Now,
                            CInfoId    = cInfo.Id,
                            UserLogin  = paser.code,
                            ProductId  = item.ProductId,
                            Barcode    = item.Code,
                            MSGType    = "SMS"
                        };

                        List <MSGPointEvent> listPointEvent = new List <MSGPointEvent>();

                        foreach (var userEvent in listEventUser)
                        {
                            // kiem tra san pham co trong su kien nay ko
                            var productEvent = userEvent.EventProducts.Where(p => p.ProductId == item.ProductId).FirstOrDefault();
                            if (productEvent != null)
                            {
                                var pointEvemt = new MSGPointEvent()
                                {
                                    EventId    = userEvent.Id,
                                    MSGPointId = hEvent.Id,
                                    Point      = productEvent.Point
                                };
                                listPointEvent.Add(pointEvemt);
                            }
                        }
                        //

                        if (listPointEvent.Count() > 0)
                        {
                            if (!productAttend.Contains(item.ProductId))
                            {
                                productAttend.Add(item.ProductId);
                            }

                            item.IsUse           = 1;
                            item.ModifyTime      = DateTime.Now;
                            db.Entry(item).State = System.Data.Entity.EntityState.Modified;

                            db.MSGPoints.Add(hEvent);

                            db.SaveChanges();

                            foreach (var pevent in listPointEvent)
                            {
                                if (map.ContainsKey(pevent.EventId))
                                {
                                    var oldPoint = Convert.ToInt32(map[pevent.EventId]);
                                    map[pevent.EventId] = oldPoint + pevent.Point;
                                }
                                else
                                {
                                    map.Add(pevent.EventId, Convert.ToInt32(pevent.Point));
                                }

                                db.MSGPointEvents.Add(pevent);



                                // luu diem cho khach hang
                                var agencyPoint = db.AgencySavePoints.Where(p => p.EventId == pevent.EventId && p.CInfoId == cInfo.Id).FirstOrDefault();

                                if (agencyPoint == null)
                                {
                                    var newAgencyPoint = new AgencySavePoint()
                                    {
                                        EventId    = pevent.EventId,
                                        CInfoId    = cInfo.Id,
                                        PointSave  = pevent.Point,
                                        CreateTime = DateTime.Now
                                    };
                                    db.AgencySavePoints.Add(newAgencyPoint);
                                }
                                else
                                {
                                    var newPoint = agencyPoint.PointSave + pevent.Point;
                                    agencyPoint.PointSave       = newPoint;
                                    agencyPoint.ModifyTime      = DateTime.Now;
                                    db.Entry(agencyPoint).State = System.Data.Entity.EntityState.Modified;
                                }

                                db.SaveChanges();
                            }
                        }
                    }
                    catch
                    {
                    }
                }
                //

                // phan qua
                string pointEvent = "";
                int    countPoint = 0;
                foreach (var item in map.Keys)
                {
                    var eventInfo = db.EventInfoes.Find(item);

                    var savePoint = eventInfo.AgencySavePoints.Where(p => p.CInfoCommon.CCode == paser.code).FirstOrDefault();
                    int?point     = 0;
                    if (savePoint != null)
                    {
                        point = savePoint.PointSave;
                    }

                    string aWard     = "";
                    var    listAward = eventInfo.AwardInfoes.OrderByDescending(p => p.Point).ToList();
                    foreach (var aWardItem in listAward)
                    {
                        if (aWardItem.Point <= point)
                        {
                            aWard = ConvertToUnsign3(aWardItem.Name);
                            break;
                        }
                    }

                    var nameEvent = ConvertToUnsign3(eventInfo.Name);

                    if (!String.IsNullOrEmpty(aWard))
                    {
                        pointEvent = " , " + aWard + " tu " + nameEvent;
                    }


                    countPoint += Convert.ToInt32(map[item]);
                }


                //


                string msgReturn = "MKH " + paser.code + " vua tich luy " + countPoint + " diem tu ";
                foreach (string item in productAttend)
                {
                    var productCheck = db.ProductInfoes.Find(item);
                    if (productCheck != null)
                    {
                        msgReturn += ConvertToUnsign3(productCheck.PName) + " ,";
                    }
                }

                msgReturn = msgReturn.Remove(msgReturn.Count() - 1, 1);

                msgReturn += ". Cam on quy khach da tham gia CT Ket noi cung phat trien cua cty CPND HAI. ";


                if (!String.IsNullOrEmpty(pointEvent))
                {
                    pointEvent = pointEvent.Remove(0, 2);
                    msgReturn += "Chuc mung MKH " + paser.code + " nhan duoc" + pointEvent + ". Cam on quy khach da tham gia CT Ket noi cung phat trien cua cty CPND HAI.";
                }

                result.message = msgReturn;
            }
            catch (Exception e)
            {
                result.status  = 0;
                result.message = e.Message;
            }

            return(result);
        }
Ejemplo n.º 9
0
        // save history
        protected void saveHistory(string barcode, string caseCode, string boxCode, ProductInfo product, string stt, decimal?quantity, WavehouseInfo wInfo)
        {
            var history = new PHistory()
            {
                Id          = Guid.NewGuid().ToString(),
                Barcode     = barcode,
                PStatus     = stt,
                BoxCode     = boxCode,
                UserSend    = user,
                WCode       = wInfo.wCode,
                WName       = wInfo.wName,
                WType       = wInfo.wType,
                ProductCode = product.Barcode,
                CreateDate  = DateTime.Now,
                CaseCode    = caseCode,
                Quantity    = quantity
            };

            db.PHistories.Add(history);
            db.SaveChanges();

            var tracking = db.PTrackings.Where(p => p.CaseCode == caseCode && p.WCode == wInfo.wCode).FirstOrDefault();


            if (tracking == null)
            {
                var pTracking = new PTracking()
                {
                    Id        = Guid.NewGuid().ToString(),
                    WCode     = wInfo.wCode,
                    WType     = wInfo.wType,
                    WName     = wInfo.wName,
                    CaseCode  = caseCode,
                    ProductId = product.Id,
                    Quantity  = quantity
                };

                if (stt == "NK")
                {
                    pTracking.ImportTime = DateTime.Now;
                }
                else
                {
                    pTracking.ExportTime = DateTime.Now;
                }
                db.PTrackings.Add(pTracking);
                db.SaveChanges();
            }
            else
            {
                if (stt == "NK")
                {
                    tracking.Quantity   = tracking.Quantity + quantity;
                    tracking.ImportTime = DateTime.Now;
                }
                else
                {
                    tracking.Quantity   = tracking.Quantity - quantity;
                    tracking.ExportTime = DateTime.Now;
                }

                db.Entry(tracking).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
        }
Ejemplo n.º 10
0
        public ActionResult ModifyProduct(ProductInfo product, string IsBox, HttpPostedFileBase Thumbnail, List <HttpPostedFileBase> files)
        {
            if (!Utitl.CheckUser(db, User.Identity.Name, "ManageProduct", 1))
            {
                return(RedirectToAction("relogin", "home"));
            }

            var productCheck = db.ProductInfoes.Find(product.Id);

            if (productCheck == null)
            {
                return(RedirectToAction("error", "home"));
            }

            var checkDb = db.ProductInfoes.Where(p => p.PCode == product.PCode).FirstOrDefault();

            if (checkDb == null)
            {
                productCheck.PCode = product.PCode;
            }

            productCheck.PName       = product.PName;
            productCheck.Unit        = product.Unit;
            productCheck.QuantityBox = product.QuantityBox;

            if (Thumbnail != null)
            {
                productCheck.Thumbnail = UploadImage(Thumbnail, "/haiupload/product", ".png");
            }



            if (IsBox != null)
            {
                productCheck.IsBox = 1;
            }
            else
            {
                productCheck.IsBox = 0;
            }

            if (files != null)
            {
                foreach (var item in files)
                {
                    var imageProduct = new ProductImage()
                    {
                        Id        = Guid.NewGuid().ToString(),
                        ProductId = productCheck.Id,
                        ImageUrl  = UploadImage(item, "/haiupload/product", ".png")
                    };
                    db.ProductImages.Add(imageProduct);
                    db.SaveChanges();
                }
            }

            db.Entry(productCheck).State = System.Data.Entity.EntityState.Modified;


            db.SaveChanges();

            return(RedirectToAction("modifyproduct", "product", new { id = productCheck.Id }));
        }