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)); }
public ActionResult AddFuncToRole(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 (isAdd && funcRole == null) { var newFuncRole = new FuncRole() { FuncId = func.Id, RoleId = role.Id, IsAll = 0 }; db.FuncRoles.Add(newFuncRole); db.SaveChanges(); return(Content("Đã add")); } if (!isAdd && funcRole != null) { db.FuncRoles.Remove(funcRole); db.SaveChanges(); return(Content("Đã xóa")); } return(Content("Không thành công.")); }
public ActionResult UpdateC1Staff(string CI, string Staff) { CI = CI.Replace("\r", ""); string[] listCI = Regex.Split(CI, "\n"); Staff = Staff.Replace("\r", ""); string[] listStaff = Regex.Split(Staff, "\n"); foreach (var itemStaff in listStaff) { var find = db.HaiStaffs.Where(p => p.Code == itemStaff.Trim()).FirstOrDefault(); if (find != null) { foreach (var itemC1 in listCI) { var checkC1 = db.C1Info.Where(p => p.Code == itemC1.Trim()).FirstOrDefault(); if (checkC1 != null) { var checkStaffC1 = find.C1Info.Where(p => p.Id == checkC1.Id).FirstOrDefault(); if (checkStaffC1 == null) { find.C1Info.Add(checkC1); } } } db.SaveChanges(); } } return(View()); }
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 })); }
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 })); }
public ActionResult Decor(HttpPostedFileBase image, string extension, string user, string token, string checkInId, string group) { if (mongoHelp.checkLoginSession(user, token)) { HaiStaff staff = db.HaiStaffs.Where(p => p.UserLogin == user).FirstOrDefault(); if (staff == null) { return(Json(new { id = "0", msg = "Sai thong tin" }, JsonRequestBehavior.AllowGet)); } var cWork = db.CalendarWorks.Find(checkInId); if (cWork == null) { return(Json(new { id = "0", msg = "Sai thong tin" }, JsonRequestBehavior.AllowGet)); } string dfolder = user + "/" + group + "/" + DateTime.Now.Date.ToString("dd-MM-yyyy"); string fsave = "~/uploadfolder/" + dfolder; bool exists = System.IO.Directory.Exists(Server.MapPath(fsave)); if (!exists) { System.IO.Directory.CreateDirectory(Server.MapPath(fsave)); } string urlThumbnail = ""; try { MemoryStream target = new MemoryStream(); image.InputStream.CopyTo(target); byte[] data = target.ToArray(); ImageUpload imageUpload = new ImageUpload { Width = 3000, isSacle = false, UploadPath = fsave, user = cWork.AgencyCode }; ImageResult imageResult = imageUpload.RenameUploadFile(data, extension); if (imageResult.Success) { urlThumbnail = "/uploadfolder/" + dfolder + "/" + imageResult.ImageName; } // save inffo var decor = new DecorImage() { Id = Guid.NewGuid().ToString(), CreateTime = DateTime.Now.TimeOfDay, DecorGroup = group, ImageUrl = urlThumbnail, CalendarWorkID = checkInId }; db.DecorImages.Add(decor); db.SaveChanges(); } catch { return(Json(new { id = "0", msg = "Image upload to fail" }, JsonRequestBehavior.AllowGet)); } return(Json(new { id = "1", msg = urlThumbnail }, JsonRequestBehavior.AllowGet)); } return(Json(new { id = "0", msg = "Faile token user" }, JsonRequestBehavior.AllowGet)); }
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 SMSResult haisms() { // update regid firebase // /api/smsapi/haisms var history = new APIHistory() { Id = Guid.NewGuid().ToString(), CreateTime = DateTime.Now, APIUrl = "/api/smsapi/haisms", Sucess = 1 }; HttpRequestHeaders headers = Request.Headers; var authInfo = checkAuth(headers); if (authInfo.status == 0) { history.Sucess = 0; history.ReturnInfo = new JavaScriptSerializer().Serialize(authInfo); db.APIHistories.Add(history); db.SaveChanges(); return(authInfo); } else { var requestContent = Request.Content.ReadAsStringAsync().Result; var jsonserializer = new JavaScriptSerializer(); SMSHistory smsHistory = new SMSHistory() { CreateTime = DateTime.Now, Id = Guid.NewGuid().ToString() }; SMSResult result = new SMSResult() { status = 0, message = "" }; history.Content = requestContent; try { var paser = jsonserializer.Deserialize <SMSRequest>(requestContent); SMSContent content = analysisContent(paser.content, paser.phone); smsHistory.PhoneNumber = paser.phone; smsHistory.ContentSend = paser.content; if (content.status == 0) { result.status = 1; // sai cu phap result.message = "Cu phap nhan tin cua Quy Khach vua thuc hien khong dung. Chi tiet lien he NVTT hoac 1800577768"; } else { if (content.isAgency) { smsHistory.AgencyType = "CII"; result = checkContent(content); } else { smsHistory.AgencyType = "FARMER"; result = checkContentFarmer(content); } } } catch (Exception e) { result.status = 0; result.message = e.Message; } smsHistory.ContentReturn = result.message; db.SMSHistories.Add(smsHistory); history.ReturnInfo = new JavaScriptSerializer().Serialize(result); history.Sucess = result.status; db.APIHistories.Add(history); db.SaveChanges(); return(result); } }
// 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(); } }
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 })); }
public ActionResult SendSMS(string phone, string messenge) { if (!Utitl.CheckUser(db, User.Identity.Name, "ManageNotification", 1)) { return(RedirectToAction("relogin", "home")); } var account = db.SmsAccounts.Find(1); string Msg = string.Empty; if (account != null) { SMScore _smsCore = new SMScore(account.BrandName, account.UserName, account.Pass); _smsCore.IPserver = account.AddressSend; _smsCore.Port = Convert.ToInt32(account.PortSend); _smsCore.SendMethod = account.Method; var listPhone = phone.Split(';'); if (listPhone.Count() == 1) { var result = _smsCore.SendSMS(messenge, listPhone[0], ref Msg); if (result) { var history = new SendSmsHistory() { Id = Guid.NewGuid().ToString(), Phone = listPhone[0], Messenge = messenge, UserSend = User.Identity.Name, CreateTime = DateTime.Now, StatusSend = "Đã gửi thành công" }; db.SendSmsHistories.Add(history); db.SaveChanges(); } else { var history = new SendSmsHistory() { Id = Guid.NewGuid().ToString(), Phone = listPhone[0], Messenge = messenge, UserSend = User.Identity.Name, CreateTime = DateTime.Now, StatusSend = Msg }; db.SendSmsHistories.Add(history); db.SaveChanges(); } } else if (listPhone.Count() > 1) { List <SMSUtl.SendMessageResult> SMSMessageResult = null; List <SMSUtl.Message> SMSMessages = new List <SMSUtl.Message>(); foreach (var item in listPhone) { if (!String.IsNullOrEmpty(item)) { SMSUtl.Message msg = new SMSUtl.Message(); msg.Phone = item; msg.Content = messenge; SMSMessages.Add(msg); } } SMSMessageResult = _smsCore.SendMultiSMS(SMSMessages, ref Msg); for (var i = 0; i < SMSMessageResult.Count(); i++) { if (SMSMessageResult[i].Status == 1) { var history = new SendSmsHistory() { Id = Guid.NewGuid().ToString(), Phone = listPhone[i], Messenge = messenge, UserSend = User.Identity.Name, CreateTime = DateTime.Now, StatusSend = "Đã gửi thành công" }; db.SendSmsHistories.Add(history); } else { var history = new SendSmsHistory() { Id = Guid.NewGuid().ToString(), Phone = listPhone[i], Messenge = messenge, UserSend = User.Identity.Name, CreateTime = DateTime.Now, StatusSend = SMSMessageResult[i].Message }; db.SendSmsHistories.Add(history); } } db.SaveChanges(); } } return(RedirectToAction("sendsms", "notification")); }
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 })); }
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 })); }