public ResultInfo LoginSession(string user, string token) { var history = new MongoHistoryAPI() { CreateTime = DateTime.Now, APIUrl = "/api/user/loginsession", Content = user + "|" + token, Sucess = 1 }; var result = new ResultInfo() { id = "1" }; if (!mongoHelper.checkLoginSession(user, token)) { result.id = "0"; result.msg = "Tài khoản bạn đã đăng nhập ở thiết bị khác."; history.Sucess = 0; } history.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(history); return(result); }
public List <SubOwner> GetC1C2(string code) { var log = new MongoHistoryAPI() { APIUrl = "/api/agency/getc1c2", CreateTime = DateTime.Now, Sucess = 1, Content = code }; var c2c1 = db.C2C1.Where(p => p.C2Code == code).ToList(); List <SubOwner> agencyC2C1 = new List <SubOwner>(); foreach (var item in c2c1) { var checkC1 = db.C1Info.Where(p => p.Code == item.C1Code).FirstOrDefault(); if (checkC1 != null) { agencyC2C1.Add(new SubOwner() { code = checkC1.Code, name = checkC1.Deputy, store = checkC1.StoreName, priority = item.Priority }); } } log.ReturnInfo = new JavaScriptSerializer().Serialize(agencyC2C1); mongoHelper.createHistoryAPI(log); return(agencyC2C1); }
public List <ProductOrderHistory> OrderProductHistory(string orderId, string productId) { var log = new MongoHistoryAPI() { APIUrl = "/api/c1order/orderproducthistory", CreateTime = DateTime.Now, Sucess = 1 }; var result = new List <ProductOrderHistory>(); var data = db.OrderProductHistories.Where(p => p.OrderId == orderId && p.ProductId == productId).OrderByDescending(p => p.CreateDate).ToList(); foreach (var item in data) { result.Add(new ProductOrderHistory() { date = item.CreateDate.Value.ToString("dd/MM/yyyy"), quantity = item.Quantity, notes = item.Notes, quantityBox = item.ProductInfo.Quantity, unit = item.ProductInfo.Unit }); } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public List <AgencyInfo> GetAgencyC1(string user, string token) { var log = new MongoHistoryAPI() { APIUrl = "/api/agency/getagencyc1", CreateTime = DateTime.Now, Sucess = 1 }; var result = new List <AgencyInfo>(); if (!mongoHelper.checkLoginSession(user, token)) { return(result); } var staff = db.HaiStaffs.Where(p => p.UserLogin == user).FirstOrDefault(); if (staff == null) { return(result); } result = GetListC1(staff); log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public async Task <LoginResult> Login() { // login // /api/rest/login // method: get HttpRequestHeaders headers = Request.Headers; LoginResult check = await Auth(headers); var history = new MongoHistoryAPI() { CreateTime = DateTime.Now, APIUrl = "/api/user/login", ReturnInfo = new JavaScriptSerializer().Serialize(check) }; if (check.id == "0") { history.Sucess = 0; } else { history.Sucess = 1; } mongoHelper.createHistoryAPI(history); return(check); }
public List <string> GetProductTask(string user, string token) { // update regid firebase // /api/rest/functionproduct var history = new MongoHistoryAPI() { CreateTime = DateTime.Now, APIUrl = "/api/product/getproducttask", Sucess = 1 }; var result = new List <string>(); try { if (!mongoHelper.checkLoginSession(user, token)) { throw new Exception("Tài khoản bạn đã đăng nhập ở thiết bị khác."); } result = GetUserFunction(user, "product"); } catch (Exception e) { history.Sucess = 0; history.Error = e.Message; } history.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(history); return(result); }
public CWorkResult ShowWork(string user) { var log = new MongoHistoryAPI() { APIUrl = "/api/calendar/showwork", CreateTime = DateTime.Now, Sucess = 1 }; var result = new CWorkResult() { id = "1", msg = "success", works = new List <CWorkInfo>() }; try { var checkStaff = db.MStaffs.Where(p => p.MUser == user).FirstOrDefault(); if (checkStaff == null) { throw new Exception("Sai thông tin"); } var works = db.get_calendar_by_staff_byday(GetIso8601WeekOfYear(DateTime.Now), DateTime.Now.Year, checkStaff.Id).ToList(); foreach (var item in works) { result.works.Add(new CWorkInfo() { store = item.Store, phone = item.Phone, lng = item.Lng == null ? 0 : item.Lng, lat = item.Lat == null ? 0 : item.Lat, address = item.AddressDetail, code = item.Code, id = item.Id, discount = item.Discount == null? 0: item.Discount }); } } catch (Exception e) { result.id = "0"; result.msg = e.Message; log.Sucess = 0; } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public MainInfoResult MainLoad() { var log = new MongoHistoryAPI() { APIUrl = "/api/user/mainload", CreateTime = DateTime.Now, Sucess = 1 }; var result = new MainInfoResult() { id = "1", msg = "success" }; try { var requestContent = Request.Content.ReadAsStringAsync().Result; var jsonserializer = new JavaScriptSerializer(); var paser = jsonserializer.Deserialize <MainInfoRequest>(requestContent); log.Content = new JavaScriptSerializer().Serialize(paser); if (!mongoHelper.checkLoginSession(paser.user, paser.token)) { throw new Exception("Tài khoản bạn đã bị đăng nhập trên thiết bị khác"); } mongoHelper.checkAndUpdateFirebase(paser.user, paser.firebaseId); // if (isAdmin(paser.user)) { result.role = "Admin"; } else { result.role = ""; } result.notices = mongoHelper.countNoticesNotRead(paser.user); } catch (Exception e) { result.id = "0"; result.msg = e.Message; log.Sucess = 0; } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public List <DecorImageResult> GetDecorImages() { var log = new MongoHistoryAPI() { APIUrl = "/api/decor/getdecorimages", CreateTime = DateTime.Now, Sucess = 1 }; var result = new List <DecorImageResult>(); try { var requestContent = Request.Content.ReadAsStringAsync().Result; var jsonserializer = new JavaScriptSerializer(); var paser = jsonserializer.Deserialize <DecorImageRequest>(requestContent); log.Content = new JavaScriptSerializer().Serialize(paser); if (!mongoHelper.checkLoginSession(paser.user, paser.token)) { throw new Exception("Wrong token and user login!"); } var staff = db.HaiStaffs.Where(p => p.UserLogin == paser.user).FirstOrDefault(); if (staff == null) { throw new Exception("Chỉ nhân viên công ty mới được quyền"); } var data = db.DecorImages.Where(p => p.CalendarWorkID == paser.checkInId).ToList(); foreach (var item in data) { result.Add(new DecorImageResult() { id = item.Id, url = HaiUtil.HostName + item.ImageUrl }); } } catch (Exception e) { log.Error = e.Message; log.Sucess = 0; } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public ProductDetailResult GetProductDetail(string user, string token, string id) { var log = new MongoHistoryAPI() { APIUrl = "/api/showinfo/getproductdetail", CreateTime = DateTime.Now, Sucess = 1 }; var result = new ProductDetailResult(); /* * if (!mongoHelper.checkLoginSession(user, token)) * return result; * * var find = db.procduct_item_detail(id).FirstOrDefault(); * * if (find == null) * return result; * * result = new ProductDetailResult() * { * id = find.Id, * code = find.PCode, * name = find.PName, * barcode = find.Barcode, * isForcus = find.Forcus, * groupId = find.GroupId, * groupName = find.GroupName, * image = HaiUtil.HostName + find.Thumbnail, * isNew = find.New, * producer = find.Producer, * describe = find.Describe, * introduce = find.Introduce, * notes = find.Notes, * other = find.Other, * unit = find.Unit, * images = new List<string>() * }; * * var imges = db.ProductImages.Where(p => p.ProductId == result.id).ToList(); * * foreach (var item in imges) * { * result.images.Add(HaiUtil.HostName + item.ImageUrl); * } * * log.ReturnInfo = new JavaScriptSerializer().Serialize(result); * mongoHelper.createHistoryAPI(log); */ return(result); }
public CheckStaffResult CheckStaff(string code, string user, string token) { // check sesion for login // /api/rest/loginsession var history = new MongoHistoryAPI() { CreateTime = DateTime.Now, APIUrl = "/api/showinfo/checkstaff", Sucess = 1, Content = "code : " + code + " ; user : "******" token : " + token }; var result = new CheckStaffResult() { id = "1" }; if (!mongoHelper.checkLoginSession(user, token)) { result.id = "0"; result.msg = "Tài khoản bạn đã đăng nhập ở thiết bị khác."; history.Sucess = 0; } else { var staff = db.HaiStaffs.Where(p => p.Code == code).FirstOrDefault(); if (staff == null) { result.id = "0"; result.msg = "Không tìm thấy nhân viên này."; history.Sucess = 0; } else { result.avatar = HaiUtil.HostName + staff.AvatarUrl; result.signature = HaiUtil.HostName + staff.SignatureUrl; result.id = "1"; result.msg = "success"; result.status = staff.Notes; } } history.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(history); return(result); }
public List <ShowProductOrderInfo> ShowProductOrder(string orderId) { var log = new MongoHistoryAPI() { APIUrl = "/api/order/showproductorder", CreateTime = DateTime.Now, Sucess = 1 }; var result = new List <ShowProductOrderInfo>(); try { var checkOrder = db.MOrders.Find(orderId); if (checkOrder == null) { throw new Exception("Sai thông tin"); } foreach (var item in checkOrder.ProductOrders) { result.Add(new ShowProductOrderInfo() { code = item.MProduct.PSizeCode, name = item.MProduct.PName, size = item.MProduct.PSize, price = item.Price.Value.ToString("C", Cultures.VietNam), priceTotal = (item.QuantityBuy * item.Price).Value.ToString("C", Cultures.VietNam), quantityBuy = (int)item.QuantityBuy, quantityReal = (int)item.QuantityReal, Id = item.ProductId }); } } catch { log.Sucess = 0; } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public ResultInfo UpdateAgencyLocation(double lat, double lng, string agencyCode) { var log = new MongoHistoryAPI() { APIUrl = "/api/info/updateagencylocation", CreateTime = DateTime.Now, Sucess = 1 }; var result = new ResultInfo() { id = "1", msg = "success" }; try { var checkAgency = db.MAgencies.Where(p => p.Code == agencyCode).FirstOrDefault(); if (checkAgency == null) { throw new Exception("Sai thông tin"); } checkAgency.Lat = lat; checkAgency.Lng = lng; db.Entry(checkAgency).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (Exception e) { result.id = "0"; result.msg = e.Message; log.Sucess = 0; } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public List <ProductOrderInfo> GetProduct(string user, string id) { var log = new MongoHistoryAPI() { APIUrl = "/api/c1order/getproduct", CreateTime = DateTime.Now, Sucess = 1 }; var result = new List <ProductOrderInfo>(); var c1Info = db.C1Info.Where(p => p.CInfoCommon.UserLogin == user).FirstOrDefault(); if (c1Info != null) { var data = db.OrderProducts.Where(p => p.OrderId == id).ToList(); foreach (var item in data) { result.Add(new ProductOrderInfo() { orderId = item.OrderId, productId = item.ProductId, productName = item.ProductInfo.PName, quantity = item.Quantity, quantityFinish = item.QuantityFinish, perPrice = item.PerPrice, price = item.PriceTotal, quantityBox = item.ProductInfo.Quantity, unit = item.ProductInfo.Unit }); } } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public List <DecorFolderResult> GetDecorFolder(string user, string token) { var log = new MongoHistoryAPI() { APIUrl = "/api/decor/getdecorfolder", CreateTime = DateTime.Now, Sucess = 1 }; var result = new List <DecorFolderResult>(); try { if (!mongoHelper.checkLoginSession(user, token)) { throw new Exception("Wrong token and user login!"); } var data = db.DecorGroups.ToList(); foreach (var item in data) { result.Add(new DecorFolderResult() { code = item.Id, name = item.Name }); } } catch (Exception e) { log.Error = e.Message; log.Sucess = 0; } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public List <ProductInfoResult> GetProduct(string user, string token) { var log = new MongoHistoryAPI() { APIUrl = "/api/showinfo/getproduct", CreateTime = DateTime.Now, Sucess = 1 }; var result = new List <ProductInfoResult>(); if (!mongoHelper.checkLoginSession(user, token)) { return(result); } result = GetProductCodeInfo(); log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public List <AgencyInfo> GetAgency(string user, string token) { var log = new MongoHistoryAPI() { APIUrl = "/api/agency/getagency", CreateTime = DateTime.Now, Sucess = 1 }; var result = new List <AgencyInfo>(); if (!mongoHelper.checkLoginSession(user, token)) { return(result); } try { var staff = db.HaiStaffs.Where(p => p.UserLogin == user).FirstOrDefault(); if (staff == null) { throw new Exception("Chỉ nhân viên công ty mới được quyền truy cập"); } result.AddRange(GetStaffC2(staff)); result.AddRange(GetStaffC1(staff)); } catch { result = new List <AgencyInfo>(); } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public ResultInfo LoginSession(string user, string token, string version) { // check sesion for login // /api/rest/loginsession var history = new MongoHistoryAPI() { CreateTime = DateTime.Now, APIUrl = "/api/user/loginsession", Content = user + "|" + token, Sucess = 1 }; var result = new ResultInfo() { id = "1" }; string versionCurrent = ConfigurationManager.AppSettings["VersionApp"]; if (version != versionCurrent) { result.id = "2"; result.msg = "Cập nhật phiên bản mới"; history.Sucess = 0; } else if (!mongoHelper.checkLoginSession(user, token)) { result.id = "0"; result.msg = "Tài khoản bạn đã đăng nhập ở thiết bị khác."; history.Sucess = 0; } history.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(history); return(result); }
public List <AgencyInfo> GetC2C1(string user, string token) { var log = new MongoHistoryAPI() { APIUrl = "/api/agency/getc2c1", CreateTime = DateTime.Now, Sucess = 1 }; var result = new List <AgencyInfo>(); try { if (!mongoHelper.checkLoginSession(user, token)) { throw new Exception("Wrong token and user login!"); } var c1Info = db.C1Info.Where(p => p.CInfoCommon.UserLogin == user).FirstOrDefault(); if (c1Info == null) { throw new Exception("Sai thong tin"); } result = GetListC2OfC1(c1Info.Code); } catch { result = new List <AgencyInfo>(); } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public ResultInfo read(string user, string notification) { var log = new MongoHistoryAPI() { APIUrl = "/api/notification/read", CreateTime = DateTime.Now, Sucess = 1 }; var result = new ResultInfo() { id = "1", msg = "success" }; mongoHelper.updateNotificationRead(user, notification); log.Content = user + "|" + notification; log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public ResultInfo StaffComplete() { var log = new MongoHistoryAPI() { APIUrl = "/api/order/staffcomplete", CreateTime = DateTime.Now, Sucess = 1 }; var result = new ResultInfo() { id = "1", msg = "success" }; try { var requestContent = Request.Content.ReadAsStringAsync().Result; var jsonserializer = new JavaScriptSerializer(); var paser = jsonserializer.Deserialize <OrderInfoRequest>(requestContent); log.Content = new JavaScriptSerializer().Serialize(paser); if (!mongoHelper.checkLoginSession(paser.user, paser.token)) { throw new Exception("Wrong token and user login!"); } DateTime dateSuggest = DateTime.ParseExact(paser.timeSuggest, "d/M/yyyy", null); CInfoCommon cinfo = db.CInfoCommons.Where(p => p.CCode == paser.code).FirstOrDefault(); HaiStaff staff = db.HaiStaffs.Where(p => p.UserLogin == paser.user).FirstOrDefault(); if (staff == null) { throw new Exception("Sai thong tin nguoi dat"); } string orderType = "order"; if (paser.inCheckIn == 1) { orderType = "checkinorder"; } else if (paser.inCheckIn == 0) { orderType = "order"; } if (String.IsNullOrEmpty(orderType)) { throw new Exception("Sai thong tin dat hang"); } // if (paser.product == null || paser.product.Count() == 0) { throw new Exception("Thieu thong tin san pham"); } if (cinfo == null) { throw new Exception("Sai thong tin khach hang"); } // create code int? number = GetOrderNumber(cinfo.BranchCode); string code = cinfo.BranchCode + (100000 + number); // tạo đơn hàng var order = new HaiOrder() { Id = Guid.NewGuid().ToString(), OrderType = orderType, ShipType = paser.shipType, PayType = paser.payType, Agency = cinfo.Id, CreateDate = DateTime.Now, OrderStatus = "process", ReceiveAddress = paser.address, Notes = paser.notes, ExpectDate = dateSuggest, BrachCode = cinfo.BranchCode, Code = code, OrderNumber = number, ReceivePhone1 = paser.phone, UserCreate = paser.user, DateCode = DateTime.Now.Date.ToString("ddMMyyyy"), DebtTimeLine = paser.debtTime, DStatus = "incomplete", C1Code = "", C1Id = "", C1Name = "" }; if (paser.c1 == "000") { order.SalePlace = "B"; } else { order.SalePlace = "CI"; var checkC1 = db.C1Info.Where(p => p.Code == paser.c1).FirstOrDefault(); if (checkC1 == null) { throw new Exception("Sai thông tin nơi lấy hàng"); } order.C1Code = checkC1.Code; order.C1Id = checkC1.Id; order.C1Name = checkC1.StoreName; } db.HaiOrders.Add(order); db.SaveChanges(); // danh sach san pham mua double?priceTotal = 0; foreach (var item in paser.product) { // kiem tra san pham var checkProduct = db.ProductInfoes.Find(item.code); if (checkProduct != null && item.quantity > 0) { double?perPrice = checkProduct.Price != null ? checkProduct.Price : 0; double?price = perPrice * item.quantity; var productOrder = new OrderProduct() { OrderId = order.Id, ModifyDate = DateTime.Now, PerPrice = checkProduct.Price, Quantity = item.quantity, ProductId = checkProduct.Id, PriceTotal = price, QuantityFinish = 0, HasBill = item.hasBill }; db.OrderProducts.Add(productOrder); db.SaveChanges(); priceTotal += price; } } if (priceTotal == 0) { db.HaiOrders.Remove(order); db.SaveChanges(); throw new Exception("Sai thong tin san pham (ma san pham) hoac so luong"); } else { order.PriceTotal = priceTotal; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); } // update process: nhan vien khoi tao OrderStaff orderStaff = new OrderStaff() { Id = Guid.NewGuid().ToString(), CreateTime = DateTime.Now, OrderId = order.Id, Notes = "Khoi tao", ProcessId = "create", StaffId = staff.Id }; db.OrderStaffs.Add(orderStaff); db.SaveChanges(); // gui thong bao // nhan vien HaiUtil.SendNotifi("Đơn hàng " + order.Code, "Bạn vừa tạo đơn hàng cho " + cinfo.CName, staff.UserLogin, db, mongoHelper); // c2 // HaiUtil.SendNotifi("Đơn hàng " + order.Code, "Bạn có 1 đơn hàng được tạo bởi nhân viên Công ty H.A.I " + staff.FullName + "(" + staff.Code + ")", cinfo.UserLogin, db, mongoHelper); } catch (Exception e) { result.id = "0"; result.msg = e.Message; log.Sucess = 0; } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public OrderConfirm Confirm() { var log = new MongoHistoryAPI() { APIUrl = "/api/order/confirm", CreateTime = DateTime.Now, Sucess = 1 }; var result = new OrderConfirm() { id = "1", msg = "success" }; try { var requestContent = Request.Content.ReadAsStringAsync().Result; var jsonserializer = new JavaScriptSerializer(); var paser = jsonserializer.Deserialize <OrderConfirmRequest>(requestContent); log.Content = new JavaScriptSerializer().Serialize(paser); if (!mongoHelper.checkLoginSession(paser.user, paser.token)) { throw new Exception("Wrong token and user login!"); } var haiStaff = db.HaiStaffs.Where(p => p.UserLogin == paser.user).FirstOrDefault(); if (haiStaff == null) { throw new Exception("Chỉ nhân viên công ty mới có quyền thực hiện"); } // check C2 C2Info c2 = db.C2Info.Where(p => p.Code == paser.agency).FirstOrDefault(); if (c2 == null) { throw new Exception("Sai thông tin khách hàng"); } if (c2.IsActive == 0) { throw new Exception("Khách hàng đang tạm khóa"); } result.agencyCode = c2.Code; result.agencyId = c2.Id; result.store = c2.StoreName; result.deputy = c2.Deputy; result.phone = c2.CInfoCommon.Phone; result.address = c2.CInfoCommon.AddressInfo; /* * result.c1 = GetC2C1(c2.Code); * * // add them * result.c1.Add(new AgencyC2C1() * { * code = "000", * name = "Chi nhánh", * priority = 0, * store = "Chi nhánh : " + haiStaff.HaiBranch.Name * }); */ // lay danh sach type var payType = db.PayTypes.OrderBy(p => p.Idx).ToList(); List <IdentityCommon> paytypeAll = new List <IdentityCommon>(); foreach (var item in payType) { paytypeAll.Add(new IdentityCommon() { code = item.Id, name = item.Name }); } result.payType = paytypeAll; // var shipType = db.ShipTypes.OrderBy(p => p.Idx).ToList(); List <IdentityCommon> shipTypeAll = new List <IdentityCommon>(); foreach (var item in shipType) { shipTypeAll.Add(new IdentityCommon() { code = item.Id, name = item.Name }); } result.shipType = shipTypeAll; // danh sach khuyen mai result.events = getEvent(paser.product, c2.CInfoCommon); } catch (Exception e) { result.id = "0"; result.msg = e.Message; log.Sucess = 0; } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public NotificationInfoResult get(string user, string token, int?page) { var log = new MongoHistoryAPI() { APIUrl = "/api/notification/get", CreateTime = DateTime.Now, Sucess = 1 }; var result = new NotificationInfoResult() { id = "1", msg = "success", data = new List <NotificationInfo>() }; try { if (!mongoHelper.checkLoginSession(user, token)) { throw new Exception("Wrong token and user login!"); } var topics = GetUserTopics(user); // last 3 month var lastMonth = DateTime.Now.Month - 3; var lastYear = DateTime.Now.Year; if (lastMonth <= 0) { lastMonth = lastMonth + 12; lastYear--; } var time = DateTime.ParseExact("01/" + lastMonth + "/" + lastYear, "dd/M/yyyy", null); int pageSize = 20; int pageNumber = (page ?? 1); result.page = pageNumber; var data = mongoHelper.getListNotification(time.ToShortDateString()).ToPagedList(pageNumber, pageSize); List <NotificationInfo> notificstions = new List <NotificationInfo>(); foreach (var item in data) { if (item.NType == "ID") { // kiem tra user trong list if (item.NCode.Contains(user)) { var info = new NotificationInfo() { id = item.GuiId, messenger = item.Messenge, title = item.Title, time = item.CreateTime.Value.ToShortDateString(), content = HaiUtil.HostName + "/notification/show/" + item.GuiId }; if (item.UserRead.Contains(user)) { info.isRead = 1; } else { info.isRead = 0; } notificstions.Add(info); } } else { // kiem tra topic foreach (var topic in topics) { if (item.NCode.Contains(topic)) { var info = new NotificationInfo() { id = item.GuiId, messenger = item.Messenge, title = item.Title, time = item.CreateTime.Value.ToShortDateString(), content = HaiUtil.HostName + "/notification/show/" + item.GuiId }; if (item.UserRead.Contains(user)) { info.isRead = 1; } else { info.isRead = 0; } notificstions.Add(info); } } } result.data = notificstions; } } catch (Exception e) { result.id = "0"; result.msg = e.Message; log.Sucess = 0; } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public LoginResult LoginActivaton() { // login // /api/rest/loginactivaton // method: get var result = new LoginResult() { id = "1", msg = "success" }; var history = new MongoHistoryAPI() { CreateTime = DateTime.Now, APIUrl = "/api/user/loginactivaton" }; try { HttpRequestHeaders headers = Request.Headers; if (!headers.Contains("Authorization")) { throw new Exception("Nead authorization info"); } string token; try { string base64Auth = headers.GetValues("Authorization").First().Replace("Basic", "").Trim(); token = XString.FromBase64(base64Auth); } catch { throw new Exception("Wrong authorization info"); } var arrtok = token.Split(':'); if (arrtok.Length != 2) { throw new Exception("Wrong authorization format"); } string user = arrtok[0]; string otp = arrtok[1]; var check = db.SMSCodes.Where(p => p.UserLogin == user && p.Code == otp && p.CStatus == 0).FirstOrDefault(); if (check == null) { throw new Exception("Không thể đăng nhập vui lòng thử lại"); } check.CStatus = 1; db.Entry(check).State = EntityState.Modified; db.SaveChanges(); var info = updateAuth(user); result.Role = info.Role; result.token = info.token; result.type = info.type; } catch (Exception e) { result.id = "0"; result.msg = e.Message;; } return(result); }
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); }
public CheckInResult CheckIn(string user, string token, string agencyId) { var log = new MongoHistoryAPI() { APIUrl = "/api/calendar/checkin", CreateTime = DateTime.Now, Sucess = 1 }; var result = new CheckInResult() { id = "1", msg = "success" }; try { if (!mongoHelper.checkLoginSession(user, token)) { throw new Exception(MRes.MSG_WRONG_TOKEN); } var checkStaff = db.MStaffs.Where(p => p.MUser == user).FirstOrDefault(); if (checkStaff == null) { throw new Exception("Sai thông tin"); } var checkAgency = db.MAgencies.Find(agencyId); if (checkAgency == null) { throw new Exception("Sai đại lý"); } var dateCode = DateTime.Now.ToString("ddMMyyyy"); var checkWork = db.CalendarWorks.Where(p => p.AgencyId == agencyId && p.StaffId == checkStaff.Id && p.CDate == dateCode).FirstOrDefault(); if (checkWork == null) { var work = new CalendarWork() { AgencyId = agencyId, CDate = dateCode, CDay = DateTime.Now.Day, ChangeTime = DateTime.Now, CMonth = DateTime.Now.Month, CountWork = 1, CYear = DateTime.Now.Year, FistTime = DateTime.Now, Id = Guid.NewGuid().ToString(), Perform = 0, StaffId = checkStaff.Id, DayOfWeek = mapDayOfWeeks[DateTime.Now.DayOfWeek] }; db.CalendarWorks.Add(work); db.SaveChanges(); result.perform = 0; result.workId = work.Id; result.des = "Ghé thăm lúc " + DateTime.Now.ToString("HH:mm") + " ngày " + DateTime.Now.ToString("dd/MM/yyyy"); } else { result.perform = checkWork.Perform; result.workId = checkWork.Id; result.des = "Ghé thăm giần nhất lúc " + checkWork.ChangeTime.Value.ToString("HH:mm") + " ngày " + checkWork.ChangeTime.Value.ToString("dd/MM/yyyy"); checkWork.ChangeTime = DateTime.Now; db.Entry(checkWork).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } catch (Exception e) { result.id = "0"; result.msg = e.Message; log.Sucess = 0; } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public CalendarWorkResult CalendarWork(string user, int?week, int?year) { var log = new MongoHistoryAPI() { APIUrl = "/api/calendar/calendarwork", CreateTime = DateTime.Now, Sucess = 1 }; var result = new CalendarWorkResult() { id = "1", msg = "success", works = new List <CalendarWorkDay>() }; if (week == null || week == 0) { week = GetIso8601WeekOfYear(DateTime.Now); } if (year == null || year == 0) { year = DateTime.Now.Year; } result.week = week; result.year = year; var firstWeekCreate = FirstDateOfWeekISO8601((int)year, (int)week); result.fDate = firstWeekCreate.ToString("dd/MM/yyyy"); result.tDate = firstWeekCreate.AddDays(5).ToString("dd/MM/yyyy"); try { var checkStaff = db.MStaffs.Where(p => p.MUser == user).FirstOrDefault(); if (checkStaff == null) { throw new Exception("Sai thông tin"); } var findCal = db.CalendarInfoes.Where(p => p.WeekOfYear == week && p.CYear == year && p.StaffId == checkStaff.Id).FirstOrDefault(); if (findCal == null) { throw new Exception("Chưa có lịch"); } var startDate = DateTime.ParseExact(findCal.FDate, "dd/MM/yyyy", null); var endDate = DateTime.ParseExact(findCal.TDate, "dd/MM/yyyy", null); for (DateTime date = startDate; date <= endDate;) { CalendarWorkDay data = new CalendarWorkDay() { date = date.ToString("dd/MM/yyyy"), dayOfWeek = mapDayOfWeeks[date.DayOfWeek], plan = new List <ShowCalendarAgency>(), work = new List <ShowCalendarAgency>() }; var planCode = date.ToString("ddMMyyyy"); var listPlan = db.CalendarPlans.Where(p => p.CalendarId == findCal.Id && p.CDate == planCode).ToList(); foreach (var item in listPlan) { data.plan.Add(new ShowCalendarAgency() { code = item.MAgency.Code, name = item.MAgency.Store, target = item.Targets.Value.ToString("C", Util.Cultures.VietNam) }); } var listWork = db.CalendarWorks.Where(p => p.StaffId == findCal.StaffId && p.CDate == planCode && p.Perform == 1).ToList(); foreach (var item in listWork) { data.work.Add(new ShowCalendarAgency() { code = item.MAgency.Code, name = item.MAgency.Store }); } result.works.Add(data); date = date.AddDays(1); } } catch (Exception e) { result.id = "0"; result.msg = e.Message; log.Sucess = 0; } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public ResultInfo CheckOut(string user, string token, string workId, string notes) { var log = new MongoHistoryAPI() { APIUrl = "/api/calendar/checkout", CreateTime = DateTime.Now, Sucess = 1 }; var result = new ResultInfo() { id = "1", msg = "success" }; try { if (!mongoHelper.checkLoginSession(user, token)) { throw new Exception(MRes.MSG_WRONG_TOKEN); } var checkStaff = db.MStaffs.Where(p => p.MUser == user).FirstOrDefault(); if (checkStaff == null) { throw new Exception("Sai thông tin"); } var checkWork = db.CalendarWorks.Find(workId); if (checkWork == null) { throw new Exception("Sai thông tin"); } if (checkWork.Perform == 1) { throw new Exception("Đã check out"); } checkWork.EndTime = DateTime.Now; checkWork.Perform = 1; checkWork.Notes = notes; db.Entry(checkWork).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (Exception e) { result.id = "0"; result.msg = e.Message; log.Sucess = 0; } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public ResultInfo Logout() { // logout // /api/rest/logout // method: post var log = new MongoHistoryAPI() { APIUrl = "/api/rest/logout", CreateTime = DateTime.Now, Sucess = 1 }; var result = new ResultInfo() { id = "1", msg = "success" }; var requestContent = Request.Content.ReadAsStringAsync().Result; log.Content = requestContent; try { HttpRequestHeaders headers = Request.Headers; if (!headers.Contains("Authorization")) { throw new Exception("Nead authorization info"); } string content; try { string base64Auth = headers.GetValues("Authorization").First().Replace("Basic", "").Trim(); content = XString.FromBase64(base64Auth); } catch { throw new Exception("Wrong authorization info"); } var arrtok = content.Split(':'); if (arrtok.Length != 2) { throw new Exception("Wrong authorization format"); } string user = arrtok[0]; string token = arrtok[1]; // check user var checkUser = db.AspNetUsers.Where(p => p.UserName == user).FirstOrDefault(); if (checkUser == null) { throw new Exception("Không thể đăng xuất"); } // if (!mongoHelper.checkLoginSession(user, token)) { throw new Exception("Tài khoản đang đăng nhập trên thiết bị khác"); } // xoa firebase id var regFirebase = db.RegFirebases.Where(p => p.UserLogin == user).FirstOrDefault(); if (regFirebase != null) { regFirebase.RegId = ""; regFirebase.ModifyDate = DateTime.Now; db.Entry(regFirebase).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } mongoHelper.updateStateAuthToken(user); mongoHelper.saveLogout(user, token); } catch { } log.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(log); return(result); }
public CheckUserLoginResult CheckUserLogin() { // login // /api/rest/checkuserlogin // method: get var history = new MongoHistoryAPI() { CreateTime = DateTime.Now, APIUrl = "/api/user/checkuserlogin" }; HttpRequestHeaders headers = Request.Headers; if (!headers.Contains("Authorization")) { throw new Exception("Nead authorization info"); } string token; try { string base64Auth = headers.GetValues("Authorization").First().Replace("Basic", "").Trim(); token = XString.FromBase64(base64Auth); } catch { throw new Exception("Wrong authorization info"); } var arrtok = token.Split(':'); if (arrtok.Length != 2) { throw new Exception("Wrong authorization format"); } string user = arrtok[0]; string phone = arrtok[1]; var result = new CheckUserLoginResult() { id = "1", msg = "success", user = user }; try { var checkUser = db.AspNetUsers.Where(p => p.UserName == user).FirstOrDefault(); if (checkUser == null) { throw new Exception("Tài khoản không hợp lệ"); } if (checkUser.AccountType == "STAFF") { var haiStaff = db.HaiStaffs.Where(p => p.UserLogin == user).FirstOrDefault(); if (haiStaff != null) { if (haiStaff.IsLock == 1) { throw new Exception("Tài khoản đang tạm khóa"); } result.id = "1"; } else { throw new Exception("Tài khoản không hợp lệ"); } } else { var check = db.CInfoCommons.Where(p => p.UserLogin == user).FirstOrDefault(); if (check != null) { result.id = "2"; result.name = check.CDeputy; result.store = check.CName; result.code = check.CCode; result.phone = check.Phone; if (check.Phone != null) { // kiem tra phone var phoneOrige = check.Phone; if (check.Phone.Substring(0, 2) == "84") { phoneOrige = "0" + check.Phone.Substring(2, check.Phone.Length - 2); } if (phone == phoneOrige) { result.id = "3"; // cho dang nhap luon bool isActive = false; var staff = db.HaiStaffs.Where(p => p.UserLogin == user).FirstOrDefault(); if (staff != null) { if (staff.IsLock != 1) { isActive = true; } } else { var agency = db.CInfoCommons.Where(p => p.UserLogin == user).FirstOrDefault(); if (agency != null) { if (check.CType == "CII") { var checkC2 = check.C2Info.FirstOrDefault(); if (checkC2 != null) { if (checkC2.IsActive == 0) { isActive = false; } } } } } if (!isActive) { throw new Exception("Tài khoản bị khóa"); } var info = updateAuth(user); result.role = info.Role; result.token = info.token; result.type = info.type; } else { string Msg = string.Empty; var account = db.SmsAccounts.Find(1); Random random = new Random(); var otp = random.Next(100000, 999999); // update otp old var allOtp = db.SMSCodes.Where(p => p.UserLogin == user && p.CStatus == 0).ToList(); foreach (var item in allOtp) { item.CStatus = 1; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); } SMSCode smsCode = new SMSCode() { Id = Guid.NewGuid().ToString(), Code = Convert.ToString(otp), CreateAt = DateTime.Now, CStatus = 0, UserLogin = user }; db.SMSCodes.Add(smsCode); db.SaveChanges(); // send sms SMScore _smsCore = new SMScore(account.BrandName, account.UserName, account.Pass); _smsCore.IPserver = account.AddressSend; _smsCore.Port = Convert.ToInt32(account.PortSend); _smsCore.SendMethod = account.Method; _smsCore.SendSMS("Cam on quy khach da dang ky, ma kich hoat cua quy khach la : " + otp, check.Phone, ref Msg); } } else { throw new Exception("Quý khách chưa đăng kí số điện thoại với HAI để nhận mà kích hoặt"); } } else { throw new Exception("Tài khoản không hợp lệ"); } } } catch (Exception e) { result.id = "0"; result.msg = e.Message; } history.ReturnInfo = new JavaScriptSerializer().Serialize(result); mongoHelper.createHistoryAPI(history); return(result); }