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 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); }