public ResultInfo CreateAgencyC2() { var log = new MongoHistoryAPI() { APIUrl = "/api/agency/createagencyc2", CreateTime = DateTime.Now, Sucess = 1 }; var result = new ResultInfo() { id = "1", msg = "success" }; var requestContent = Request.Content.ReadAsStringAsync().Result; try { var jsonserializer = new JavaScriptSerializer(); var paser = jsonserializer.Deserialize <AgencyCreateRequest>(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 tạo"); } /* * if (checkC1 == null) * checkC1 = db.C1Info.Where(p => p.Code == "0000000000").FirstOrDefault(); */ var agencyCode = GetAgencyCodeTemp(staff.HaiBranch.Code); CInfoCommon cInfo = new CInfoCommon() { Id = Guid.NewGuid().ToString(), AddressInfo = paser.address, BranchCode = staff.HaiBranch.Code, BusinessLicense = paser.businessLicense, CRank = paser.rank, CDeputy = paser.deputy, CName = paser.name, CreateTime = DateTime.Now, ProvinceName = paser.province, DistrictName = paser.district, Phone = paser.phone, IdentityCard = paser.identityCard, CType = "CII", TaxCode = paser.taxCode, Lat = paser.lat, Lng = paser.lng, CCode = agencyCode, WardName = paser.ward, Country = paser.country }; db.CInfoCommons.Add(cInfo); db.SaveChanges(); C2Info c2 = new C2Info() { Id = Guid.NewGuid().ToString(), StoreName = paser.name, Deputy = paser.deputy, IsActive = 0, Code = agencyCode, InfoId = cInfo.Id, CStatus = 1 }; db.C2Info.Add(c2); db.SaveChanges(); // db.Entry(staff).State = System.Data.Entity.EntityState.Modified; // db.SaveChanges(); var staffC2 = new StaffWithC2() { C2Id = c2.Id, StaffId = staff.Id, GroupChoose = paser.group }; db.StaffWithC2.Add(staffC2); db.SaveChanges(); var checkC1 = db.C1Info.Where(p => p.Code == paser.c1Id).FirstOrDefault(); // import c1 if (checkC1 != null) { var c2C1Add = new C2C1() { C1Code = checkC1.Code, C2Code = agencyCode, Id = Guid.NewGuid().ToString(), Priority = 1, ModifyDate = DateTime.Now }; db.C2C1.Add(c2C1Add); db.SaveChanges(); } // save info var agencyImage = new SaveAgencyShopImage() { Id = Guid.NewGuid().ToString(), AddressFull = paser.address, Cinfo = cInfo.Id, Country = paser.country, District = paser.district, Lat = paser.lat, Province = paser.province, CreateTime = DateTime.Now, StaffId = staff.Id, Lng = paser.lng, Ward = paser.ward, ImagePath = paser.image }; db.SaveAgencyShopImages.Add(agencyImage); } 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 async Task <ActionResult> UpdateAgencyC2V2(HttpPostedFileBase files) { List <string> listFail = new List <string>(); if (files != null && files.ContentLength > 0) { string extension = System.IO.Path.GetExtension(files.FileName); if (extension.Equals(".xlsx")) { string fileSave = "cii_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + extension; string path = Server.MapPath("~/temp/" + fileSave); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } files.SaveAs(path); FileInfo newFile = new FileInfo(path); var package = new ExcelPackage(newFile); ExcelWorksheet sheet = package.Workbook.Worksheets[1]; int totalRows = sheet.Dimension.End.Row; int totalCols = sheet.Dimension.End.Column; for (int i = 2; i <= totalRows; i++) { string code = Convert.ToString(sheet.Cells[i, 1].Value); var check = db.C2Info.Where(p => p.Code == code).FirstOrDefault(); if (check == null && !String.IsNullOrEmpty(code)) { code = code.ToUpper(); string branchCode = Convert.ToString(sheet.Cells[i, 9].Value).Trim(); var branch = db.HaiBranches.Where(p => p.Code == branchCode).FirstOrDefault(); if (branch != null) { string storeName = Convert.ToString(sheet.Cells[i, 2].Value); string deputy = Convert.ToString(sheet.Cells[i, 3].Value); string identityCard = Convert.ToString(sheet.Cells[i, 5].Value); string phone = Convert.ToString(sheet.Cells[i, 4].Value); string bussinessLicence = Convert.ToString(sheet.Cells[i, 6].Value); string addressInfo = Convert.ToString(sheet.Cells[i, 7].Value); string c1Code = Convert.ToString(sheet.Cells[i, 10].Value); var c1Check = db.C1Info.Where(p => p.Code == c1Code).FirstOrDefault(); if (c1Check == null) { c1Check = db.C1Info.Where(p => p.Code == "0000000000").FirstOrDefault(); } var cInfo = new CInfoCommon() { Id = Guid.NewGuid().ToString(), CName = storeName, IdentityCard = identityCard, AddressInfo = addressInfo, Phone = phone, CreateTime = DateTime.Now, CType = "CII", BranchCode = branch.Code, CCode = code, CDeputy = deputy }; var c2 = new C2Info() { Id = Guid.NewGuid().ToString(), InfoId = cInfo.Id, Code = code, IsActive = 1, StoreName = storeName, Deputy = deputy }; db.CInfoCommons.Add(cInfo); db.SaveChanges(); db.C2Info.Add(c2); db.SaveChanges(); // tao tai khoan var user = new ApplicationUser() { UserName = cInfo.CCode, IsActivced = 1, FullName = cInfo.CDeputy, AccountType = "CII" }; var result = await UserManager.CreateAsync(user, cInfo.Phone); if (result.Succeeded) { cInfo.UserLogin = user.UserName; db.Entry(cInfo).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); result = UserManager.AddToRole(user.Id, "Guest"); } else { listFail.Add(code + " ko tao dc tai khoan"); } } else { listFail.Add(code + " sai ma chi nhanh"); } } else { listFail.Add(code + " da tao"); } } } } return(View(listFail)); }