public string UpdateLocationBySecId(string token) { token = TokenManager.readToken(HttpContext.Current.Request); int sectionId = 0; int res = 0; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string newloclist = ""; List <locations> newlocObj = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemObject") { newloclist = c.Value.Replace("\\", string.Empty); newloclist = newloclist.Trim('"'); newlocObj = JsonConvert.DeserializeObject <List <locations> >(newloclist, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None }); break; } } using (incposdbEntities entity = new incposdbEntities()) { var oldloc = entity.locations.Where(p => p.sectionId == sectionId); if (oldloc.Count() > 0) { entity.locations.RemoveRange(oldloc); } if (newlocObj.Count() > 0) { foreach (locations newlocrow in newlocObj) { newlocrow.sectionId = sectionId; if (newlocrow.createDate == null) { newlocrow.createDate = DateTime.Now; newlocrow.updateDate = DateTime.Now; newlocrow.updateUserId = newlocrow.createUserId; } else { newlocrow.updateDate = DateTime.Now; } } entity.locations.AddRange(newlocObj); } res = entity.SaveChanges(); return(TokenManager.GenerateToken(res)); } } }
public IHttpActionResult Delete(int medalId, int userId, bool final) { var re = Request; var headers = re.Headers; string token = ""; if (headers.Contains("APIKey")) { token = headers.GetValues("APIKey").First(); } Validation validation = new Validation(); bool valid = validation.CheckApiKey(token); if (valid) { if (final) { try { using (incposdbEntities entity = new incposdbEntities()) { medals medalObj = entity.medals.Find(medalId); entity.medals.Remove(medalObj); entity.SaveChanges(); return Ok("medal is Deleted Successfully"); } } catch { return NotFound(); } } else { try { using (incposdbEntities entity = new incposdbEntities()) { medals medalObj = entity.medals.Find(medalId); medalObj.isActive = 0; medalObj.updateUserId = userId; medalObj.updateDate = DateTime.Now; entity.SaveChanges(); return Ok("Deleted Successfully"); } } catch { return Ok("Not Deleted"); } } } else return Ok("isActive Not changed"); }
public string fallItem(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { try { string newObject = ""; inventoryItemLocation Object = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemObject") { newObject = c.Value.Replace("\\", string.Empty); newObject = newObject.Trim('"'); Object = JsonConvert.DeserializeObject <inventoryItemLocation>(newObject, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } using (incposdbEntities entity = new incposdbEntities()) { var unitEntity = entity.Set <pos>(); var tmpItem = entity.inventoryItemLocation.Where(p => p.id == Object.id).FirstOrDefault(); tmpItem.notes = Object.notes; tmpItem.isFalls = true; tmpItem.updateDate = DateTime.Now; tmpItem.updateUserId = Object.updateUserId; tmpItem.fallCause = Object.fallCause; message = tmpItem.id.ToString(); entity.SaveChanges(); } } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } return(TokenManager.GenerateToken(message)); }
public string Save(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string obj = ""; notificationUser Object = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemObject") { obj = c.Value.Replace("\\", string.Empty); obj = obj.Trim('"'); Object = JsonConvert.DeserializeObject <notificationUser>(obj, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } try { using (incposdbEntities entity = new incposdbEntities()) { var notEntity = entity.Set <notificationUser>(); Object.createDate = DateTime.Now; Object.updateDate = DateTime.Now; Object.updateUserId = Object.createUserId; notificationUser not = notEntity.Add(Object); entity.SaveChanges(); message = not.notUserId.ToString(); return(TokenManager.GenerateToken(message)); } } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } }
public string UpdateImage(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var re = Request; var headers = re.Headers; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string userObject = ""; users userObj = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemObject") { userObject = c.Value.Replace("\\", string.Empty); userObject = userObject.Trim('"'); userObj = JsonConvert.DeserializeObject <users>(userObject, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } try { users user; using (incposdbEntities entity = new incposdbEntities()) { var userEntity = entity.Set <users>(); user = entity.users.Where(p => p.userId == userObj.userId).First(); user.image = userObj.image; entity.SaveChanges(); } message = user.userId.ToString(); return(TokenManager.GenerateToken(message)); } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } }
public string updateIsonline(string token) { //string Object string message = ""; token = TokenManager.readToken(HttpContext.Current.Request); var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { bool isOnlineServer = false; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "isOnlineServer") { isOnlineServer = bool.Parse(c.Value); } } try { using (incposdbEntities entity = new incposdbEntities()) { var locationEntity = entity.Set <ProgramDetails>(); var packsl = entity.ProgramDetails.ToList(); var packs = packsl.FirstOrDefault(); packs.isOnlineServer = isOnlineServer; entity.SaveChanges(); message = packs.id.ToString(); // entity.SaveChanges(); } return(TokenManager.GenerateToken(message)); } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } }
public string UpdateBalance(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { int agentId = 0; decimal balance = 0; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "agentId") { agentId = int.Parse(c.Value); } else if (c.Type == "balance") { balance = int.Parse(c.Value); } } try { agents agent; using (incposdbEntities entity = new incposdbEntities()) { var agentEntity = entity.Set <agents>(); agent = entity.agents.Where(p => p.agentId == agentId).First(); agent.balance = balance; entity.SaveChanges(); } message = agent.agentId.ToString(); return(TokenManager.GenerateToken(message)); } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } }
public string Delete(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { try { int errorId = 0; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemId") { errorId = int.Parse(c.Value); } } using (incposdbEntities entity = new incposdbEntities()) { error objectDelete = entity.error.Find(errorId); entity.error.Remove(objectDelete); message = entity.SaveChanges().ToString(); return(TokenManager.GenerateToken(message)); } } catch { message = "-1"; return(TokenManager.GenerateToken(message)); } } }
public string UpdateImage(string token) { //public String Save(string token)string docImageObject //{ //string Object string message = ""; token = TokenManager.readToken(HttpContext.Current.Request); var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string Object = ""; docImages newObject = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "Object") { Object = c.Value.Replace("\\", string.Empty); Object = Object.Trim('"'); newObject = JsonConvert.DeserializeObject <docImages>(Object, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } if (newObject != null) { if (newObject.updateUserId == 0 || newObject.updateUserId == null) { Nullable <int> id = null; newObject.updateUserId = id; } if (newObject.createUserId == 0 || newObject.createUserId == null) { Nullable <int> id = null; newObject.createUserId = id; } try { docImages docImage; using (incposdbEntities entity = new incposdbEntities()) { var docImgEntity = entity.Set <docImages>(); docImage = entity.docImages.Where(p => p.id == newObject.id).First(); docImage.image = newObject.image; entity.SaveChanges(); } return(TokenManager.GenerateToken(docImage.id.ToString())); } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } else { return(TokenManager.GenerateToken(message)); } } //var re = Request; //var headers = re.Headers; //string token = ""; //if (headers.Contains("APIKey")) //{ // token = headers.GetValues("APIKey").First(); //} //Validation validation = new Validation(); //bool valid = validation.CheckApiKey(token); //docImageObject = docImageObject.Replace("\\", string.Empty); //docImageObject = docImageObject.Trim('"'); //if (valid) //{ // docImages docImageObj = JsonConvert.DeserializeObject<docImages>(docImageObject, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None }); // if (docImageObj.updateUserId == 0 || docImageObj.updateUserId == null) // { // Nullable<int> id = null; // docImageObj.updateUserId = id; // } // if (docImageObj.createUserId == 0 || docImageObj.createUserId == null) // { // Nullable<int> id = null; // docImageObj.createUserId = id; // } // try // { // docImages docImage; // using (incposdbEntities entity = new incposdbEntities()) // { // var docImgEntity = entity.Set<docImages>(); // docImage = entity.docImages.Where(p => p.id == docImageObj.id).First(); // docImage.image = docImageObj.image; // entity.SaveChanges(); // } // return docImage.id; // } // catch { return 0; } //} //else // return 0; }
public string Save(string token) { //public string Save(string token) //string Object string newObject string message = ""; token = TokenManager.readToken(HttpContext.Current.Request); var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string Object = ""; usersLogs newObject = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "Object") { Object = c.Value.Replace("\\", string.Empty); Object = Object.Trim('"'); newObject = JsonConvert.DeserializeObject <usersLogs>(Object, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } if (newObject != null) { usersLogs tmpObject = null; try { if (newObject.posId == 0 || newObject.posId == null) { Nullable <int> id = null; newObject.posId = id; } if (newObject.userId == 0 || newObject.userId == null) { Nullable <int> id = null; newObject.userId = id; } using (incposdbEntities entity = new incposdbEntities()) { var locationEntity = entity.Set <usersLogs>(); if (newObject.logId == 0 || newObject.logId == null) { // signIn newObject.sInDate = DateTime.Now; locationEntity.Add(newObject); entity.SaveChanges(); message = newObject.logId.ToString(); //sign out old user using (incposdbEntities entity2 = new incposdbEntities()) { List <usersLogs> ul = new List <usersLogs>(); List <usersLogs> locationE = entity2.usersLogs.ToList(); ul = locationE.Where(s => s.sOutDate == null && ((DateTime.Now - (DateTime)s.sInDate).TotalHours >= 8)).ToList(); if (ul != null) { foreach (usersLogs row in ul) { row.sOutDate = DateTime.Now; entity2.SaveChanges(); } } } } else {//signOut tmpObject = entity.usersLogs.Where(p => p.logId == newObject.logId).FirstOrDefault(); tmpObject.logId = newObject.logId; // tmpObject.sInDate=newObject.sInDate; tmpObject.sOutDate = DateTime.Now; // tmpObject.posId=newObject.posId; // tmpObject.userId = newObject.userId; entity.SaveChanges(); message = tmpObject.logId.ToString(); } // entity.SaveChanges(); } return(TokenManager.GenerateToken(message)); } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } return(TokenManager.GenerateToken(message)); } //var re = Request; //var headers = re.Headers; //string token = ""; //string message = ""; //if (headers.Contains("APIKey")) //{ // token = headers.GetValues("APIKey").First(); //} //Validation validation = new Validation(); //bool valid = validation.CheckApiKey(token); //if (valid) //{ // Object = Object.Replace("\\", string.Empty); // Object = Object.Trim('"'); // usersLogs newObject = JsonConvert.DeserializeObject<usersLogs>(Object, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None }); // if (newObject.posId == 0 || newObject.posId == null) // { // Nullable<int> id = null; // newObject.posId = id; // } // if (newObject.userId == 0 || newObject.userId == null) // { // Nullable<int> id = null; // newObject.userId = id; // } // try // { // using (incposdbEntities entity = new incposdbEntities()) // { // var locationEntity = entity.Set<usersLogs>(); // if (newObject.logId == 0 || newObject.logId == null) // { // // signIn // newObject.sInDate = DateTime.Now; // locationEntity.Add(newObject); // entity.SaveChanges(); // message = newObject.logId.ToString(); // //sign out old user // using (incposdbEntities entity2 = new incposdbEntities()) // { // List<usersLogs> ul = new List<usersLogs>(); // List<usersLogs> locationE = entity2.usersLogs.ToList(); // ul = locationE.Where(s => s.sOutDate == null && // ( (DateTime.Now-(DateTime)s.sInDate).TotalHours>=24)).ToList(); // if (ul != null) // { // foreach(usersLogs row in ul) // { // row.sOutDate = DateTime.Now; // entity2.SaveChanges(); // } // } // } // } // else // {//signOut // var tmpObject = entity.usersLogs.Where(p => p.logId == newObject.logId).FirstOrDefault(); // tmpObject.logId = newObject.logId; // // tmpObject.sInDate=newObject.sInDate; // tmpObject.sOutDate= DateTime.Now; // // tmpObject.posId=newObject.posId; // // tmpObject.userId = newObject.userId; // entity.SaveChanges(); // message = tmpObject.logId.ToString(); // } // // entity.SaveChanges(); // } // } // catch // { // message = "-1"; // } //} //return message; }
////////////////////// /// public string Save(usersLogs newObject) { //public string Save(string token) //string Object string newObject string message = ""; if (newObject != null) { usersLogs tmpObject = null; try { if (newObject.posId == 0 || newObject.posId == null) { Nullable <int> id = null; newObject.posId = id; } if (newObject.userId == 0 || newObject.userId == null) { Nullable <int> id = null; newObject.userId = id; } using (incposdbEntities entity = new incposdbEntities()) { var locationEntity = entity.Set <usersLogs>(); if (newObject.logId == 0 || newObject.logId == null) { // signIn // sign out old using (incposdbEntities entity2 = new incposdbEntities()) { List <usersLogs> ul = new List <usersLogs>(); List <usersLogs> locationE = entity2.usersLogs.ToList(); ul = locationE.Where(s => s.sOutDate == null && ((DateTime.Now - (DateTime)s.sInDate).TotalHours >= 8) || (s.userId == newObject.userId && s.sOutDate == null)).ToList(); if (ul != null) { foreach (usersLogs row in ul) { row.sOutDate = DateTime.Now; entity2.SaveChanges(); } } } newObject.sInDate = DateTime.Now; locationEntity.Add(newObject); entity.SaveChanges(); message = newObject.logId.ToString(); //sign out old user } else {//signOut tmpObject = entity.usersLogs.Where(p => p.logId == newObject.logId).FirstOrDefault(); tmpObject.logId = newObject.logId; // tmpObject.sInDate=newObject.sInDate; tmpObject.sOutDate = DateTime.Now; // tmpObject.posId=newObject.posId; // tmpObject.userId = newObject.userId; entity.SaveChanges(); message = tmpObject.logId.ToString(); } // entity.SaveChanges(); } return(message); } catch { message = "0"; return(message); } } else { return("0"); } }
public string Delete(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { int propertyItemId = 0; int userId = 0; Boolean final = false; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemId") { propertyItemId = int.Parse(c.Value); } else if (c.Type == "userId") { userId = int.Parse(c.Value); } else if (c.Type == "final") { final = bool.Parse(c.Value); } } if (final) { try { using (incposdbEntities entity = new incposdbEntities()) { propertiesItems PropertDelete = entity.propertiesItems.Find(propertyItemId); entity.propertiesItems.Remove(PropertDelete); message = entity.SaveChanges().ToString(); return(TokenManager.GenerateToken(message)); } } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } else { try { using (incposdbEntities entity = new incposdbEntities()) { propertiesItems PropertDelete = entity.propertiesItems.Find(propertyItemId); PropertDelete.isActive = 0; PropertDelete.updateUserId = userId; PropertDelete.updateDate = DateTime.Now; message = entity.SaveChanges().ToString(); return(TokenManager.GenerateToken(message)); } } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } } }
public string checkOtherUser(string token) { //public string GetPurinv(string token)int userId string message = ""; token = TokenManager.readToken(HttpContext.Current.Request); var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { int userId = 0; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "userId") { userId = int.Parse(c.Value); } } try { using (incposdbEntities entity = new incposdbEntities()) { List <usersLogs> List = entity.usersLogs.Where(S => S.userId == userId && S.sOutDate == null).ToList(); if (List != null) { foreach (usersLogs row in List) { row.sOutDate = DateTime.Now; message = entity.SaveChanges().ToString(); } // message = List.LastOrDefault().sOutDate.ToString(); // return Ok(msg); } else { message = "-1"; // return Ok("none"); } return(TokenManager.GenerateToken(message)); } // return TokenManager.GenerateToken(item); } catch { return(TokenManager.GenerateToken("0")); } } //var re = Request; //var headers = re.Headers; //string token = ""; //string msg = ""; //if (headers.Contains("APIKey")) //{ // token = headers.GetValues("APIKey").First(); //} //Validation validation = new Validation(); //bool valid = validation.CheckApiKey(token); //if (valid) // APIKey is valid //{ // using (incposdbEntities entity = new incposdbEntities()) // { // List<usersLogs> List = entity.usersLogs.Where(S => S.userId == userId && S.sOutDate == null).ToList(); // if(List !=null) // { // foreach(usersLogs row in List) // { // row.sOutDate = DateTime.Now; // entity.SaveChanges(); // } // msg = List.LastOrDefault().sOutDate.ToString(); // return Ok(msg); // } // else { return Ok("none"); } // } //} ////else //return Ok("error"); }
public string Save(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string couponsInvoicesObject = ""; int invoiceId = 0; string invType = ""; List <couponsInvoices> Object = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemObject") { couponsInvoicesObject = c.Value.Replace("\\", string.Empty); couponsInvoicesObject = couponsInvoicesObject.Trim('"'); Object = JsonConvert.DeserializeObject <List <couponsInvoices> >(couponsInvoicesObject, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None }); //break; } else if (c.Type == "invoiceId") { invoiceId = int.Parse(c.Value); } else if (c.Type == "invType") { invType = c.Value; } } using (incposdbEntities entity = new incposdbEntities()) { if (invType == "sd" || invType == "qd") { var oldList = entity.couponsInvoices.Where(p => p.InvoiceId == invoiceId); if (oldList.Count() > 0) { entity.couponsInvoices.RemoveRange(oldList); } if (Object.Count() > 0) { foreach (couponsInvoices coupon in Object) { //coupon.userId = userId; if (coupon.createDate == null) { coupon.createDate = DateTime.Now; coupon.updateDate = DateTime.Now; coupon.updateUserId = coupon.createUserId; } else { coupon.updateDate = DateTime.Now; } } entity.couponsInvoices.AddRange(Object); } entity.SaveChanges(); } else { var oldList = entity.couponsInvoices.Where(x => x.InvoiceId == invoiceId).Select(x => new { x.couponId, x.id }).ToList(); for (int i = 0; i < oldList.Count; i++)// loop to remove not exist coupon { int exist = 0; coupons c = entity.coupons.Find(oldList[i].couponId); int couponId = (int)oldList[i].couponId; var tci = entity.couponsInvoices.Where(x => x.couponId == couponId && x.InvoiceId == invoiceId).FirstOrDefault(); couponsInvoices ci = entity.couponsInvoices.Find(tci.id); if (Object != null && Object.Count > 0) { var isExist = Object.Find(x => x.couponId == oldList[i].couponId); if (isExist == null) { exist = 0; } else { exist = 1; } } //return exist; if (exist == 0)// remove coupon from invoice { c.remainQ++; entity.couponsInvoices.Remove(ci); } else // edit previously added coupons { ci.discountType = c.discountType; ci.discountValue = c.discountValue; ci.updateDate = DateTime.Now; } entity.SaveChanges(); } foreach (couponsInvoices coupon in Object)// loop to add new coupons { Boolean isInList = false; if (oldList != null) { var old = oldList.ToList().Find(x => x.couponId == coupon.couponId); if (old != null) { isInList = true; } } if (!isInList) { if (coupon.updateUserId == 0 || coupon.updateUserId == null) { Nullable <int> id = null; coupon.updateUserId = id; } if (coupon.createUserId == 0 || coupon.createUserId == null) { Nullable <int> id = null; coupon.createUserId = id; } coupon.createDate = DateTime.Now; coupon.updateDate = DateTime.Now; coupon.updateUserId = coupon.createUserId; entity.couponsInvoices.Add(coupon); entity.SaveChanges(); coupons c = entity.coupons.Find(coupon.couponId); c.remainQ--; entity.SaveChanges(); } } try { entity.SaveChanges(); } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } } message = "1"; return(TokenManager.GenerateToken(message)); } }
public string Save(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string propItemObjects = ""; propertiesItems propertyItemObject = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemObject") { propItemObjects = c.Value.Replace("\\", string.Empty); propItemObjects = propItemObjects.Trim('"'); propertyItemObject = JsonConvert.DeserializeObject <propertiesItems>(propItemObjects, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } if (propertyItemObject.updateUserId == 0 || propertyItemObject.updateUserId == null) { Nullable <int> id = null; propertyItemObject.updateUserId = id; } if (propertyItemObject.createUserId == 0 || propertyItemObject.createUserId == null) { Nullable <int> id = null; propertyItemObject.createUserId = id; } try { using (incposdbEntities entity = new incposdbEntities()) { propertiesItems tmpPropertyItem = new propertiesItems(); var propItemEntity = entity.Set <propertiesItems>(); if (propertyItemObject.propertyItemId == 0) { propertyItemObject.createDate = DateTime.Now; propertyItemObject.updateDate = DateTime.Now; propertyItemObject.updateUserId = propertyItemObject.createUserId; tmpPropertyItem = propItemEntity.Add(propertyItemObject); entity.SaveChanges(); message = tmpPropertyItem.propertyItemId.ToString(); return(TokenManager.GenerateToken(message)); } else { tmpPropertyItem = entity.propertiesItems.Where(p => p.propertyItemId == propertyItemObject.propertyItemId).FirstOrDefault(); tmpPropertyItem.name = propertyItemObject.name; tmpPropertyItem.propertyId = propertyItemObject.propertyId; tmpPropertyItem.isDefault = propertyItemObject.isDefault; tmpPropertyItem.updateDate = DateTime.Now; tmpPropertyItem.updateUserId = propertyItemObject.updateUserId; tmpPropertyItem.isActive = propertyItemObject.isActive; entity.SaveChanges(); message = tmpPropertyItem.propertyItemId.ToString(); return(TokenManager.GenerateToken(message)); } } } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } }
public string Delete(string token) { //public String Save(string token)int docId //{ //string Object string message = ""; token = TokenManager.readToken(HttpContext.Current.Request); var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { int docId = 0; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "docId") { docId = int.Parse(c.Value); } } try { using (incposdbEntities entity = new incposdbEntities()) { docImages docImageObj = entity.docImages.Find(docId); entity.docImages.Remove(docImageObj); entity.SaveChanges(); // delete image from folder //var files = Directory.GetFiles(System.Web.Hosting.HostingEnvironment.MapPath("~\\images\\docImage"), docImageObj.image); string tmpPath = System.IO.Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~\\images\\docImage"), docImageObj.image); if (File.Exists(tmpPath)) { File.Delete(tmpPath); } // return Ok("Serial is Deleted Successfully"); return(TokenManager.GenerateToken("1")); } } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } //var re = Request; //var headers = re.Headers; //string token = ""; //if (headers.Contains("APIKey")) //{ // token = headers.GetValues("APIKey").First(); //} //Validation validation = new Validation(); //bool valid = validation.CheckApiKey(token); //if (valid) //{ // try // { // using (incposdbEntities entity = new incposdbEntities()) // { // docImages docImageObj = entity.docImages.Find(docId); // entity.docImages.Remove(docImageObj); // entity.SaveChanges(); // // delete image from folder // //var files = Directory.GetFiles(System.Web.Hosting.HostingEnvironment.MapPath("~\\images\\docImage"), docImageObj.image); // string tmpPath = System.IO.Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~\\images\\docImage"), docImageObj.image); // if (File.Exists(tmpPath)) // { // File.Delete(tmpPath); // } // return Ok("Serial is Deleted Successfully"); // } // } // catch { return NotFound(); } //} //else // return NotFound(); }
public string Delete(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { int delUserId = 0; int userId = 0; Boolean final = false; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "delUserId") { delUserId = int.Parse(c.Value); } else if (c.Type == "userId") { userId = int.Parse(c.Value); } else if (c.Type == "final") { final = bool.Parse(c.Value); } } if (final) { try { using (incposdbEntities entity = new incposdbEntities()) { entity.categoryuser.RemoveRange(entity.categoryuser.Where(x => x.userId == delUserId)); users usersDelete = entity.users.Find(delUserId); entity.users.Remove(usersDelete); message = entity.SaveChanges().ToString(); return(TokenManager.GenerateToken(message)); } } catch { return(TokenManager.GenerateToken("0")); } } else { try { using (incposdbEntities entity = new incposdbEntities()) { users userDelete = entity.users.Find(delUserId); userDelete.isActive = 0; userDelete.updateDate = DateTime.Now; userDelete.updateUserId = userId; message = entity.SaveChanges().ToString(); return(TokenManager.GenerateToken(message)); } } catch { return(TokenManager.GenerateToken("0")); } } } }
public string Save(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string couponObject = ""; coupons Object = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemObject") { couponObject = c.Value.Replace("\\", string.Empty); couponObject = couponObject.Trim('"'); Object = JsonConvert.DeserializeObject <coupons>(couponObject, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } try { using (incposdbEntities entity = new incposdbEntities()) { coupons tmpcoupon = new coupons(); var couponEntity = entity.Set <coupons>(); if (Object.cId == 0) { Object.createDate = DateTime.Now; Object.updateDate = DateTime.Now; Object.updateUserId = Object.createUserId; couponEntity.Add(Object); tmpcoupon = couponEntity.Add(Object); entity.SaveChanges(); message = tmpcoupon.cId.ToString(); return(TokenManager.GenerateToken(message)); } else { tmpcoupon = entity.coupons.Where(p => p.cId == Object.cId).FirstOrDefault(); tmpcoupon.name = Object.name; tmpcoupon.code = Object.code; tmpcoupon.isActive = Object.isActive; tmpcoupon.discountType = Object.discountType; tmpcoupon.discountValue = Object.discountValue; tmpcoupon.startDate = Object.startDate; tmpcoupon.endDate = Object.endDate; tmpcoupon.notes = Object.notes; tmpcoupon.quantity = Object.quantity; tmpcoupon.remainQ = Object.remainQ; tmpcoupon.invMin = Object.invMin; tmpcoupon.invMax = Object.invMax; tmpcoupon.updateDate = DateTime.Now;// server current date; tmpcoupon.updateUserId = Object.updateUserId; tmpcoupon.barcode = Object.barcode; entity.SaveChanges(); message = tmpcoupon.cId.ToString(); return(TokenManager.GenerateToken(message)); } } } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } }
public string Save(string token) { //string Object string message = ""; token = TokenManager.readToken(HttpContext.Current.Request); var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string Object = ""; printers newObject = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "Object") { Object = c.Value.Replace("\\", string.Empty); Object = Object.Trim('"'); newObject = JsonConvert.DeserializeObject <printers>(Object, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } if (newObject != null) { printers tmpObject; if (newObject.updateUserId == 0 || newObject.updateUserId == null) { Nullable <int> id = null; newObject.updateUserId = id; } if (newObject.createUserId == 0 || newObject.createUserId == null) { Nullable <int> id = null; newObject.createUserId = id; } try { using (incposdbEntities entity = new incposdbEntities()) { var locationEntity = entity.Set <printers>(); if (newObject.printerId == 0) { newObject.createDate = DateTime.Now; newObject.updateDate = DateTime.Now; newObject.updateUserId = newObject.createUserId; locationEntity.Add(newObject); entity.SaveChanges(); message = newObject.printerId.ToString(); } else { tmpObject = entity.printers.Where(p => p.printerId == newObject.printerId).FirstOrDefault(); tmpObject.updateDate = DateTime.Now; tmpObject.updateUserId = newObject.updateUserId; tmpObject.name = newObject.name; // tmpObject.printerId = newObject.printerId; tmpObject.printFor = newObject.printFor; entity.SaveChanges(); message = tmpObject.printerId.ToString(); } // entity.SaveChanges(); } return(TokenManager.GenerateToken(message)); } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } return(TokenManager.GenerateToken(message)); } //var re = Request; // //string token = ""; //string message = ""; //if (headers.Contains("APIKey")) //{ // token = headers.GetValues("APIKey").First(); //} //Validation validation = new Validation(); //bool valid = validation.CheckApiKey(token); //if (valid) //{ // Object = Object.Replace("\\", string.Empty); // Object = Object.Trim('"'); // printers newObject = JsonConvert.DeserializeObject<printers>(Object, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None }); // if (newObject.updateUserId == 0 || newObject.updateUserId == null) // { // Nullable<int> id = null; // newObject.updateUserId = id; // } // if (newObject.createUserId == 0 || newObject.createUserId == null) // { // Nullable<int> id = null; // newObject.createUserId = id; // } // try // { // using (incposdbEntities entity = new incposdbEntities()) // { // var locationEntity = entity.Set<printers>(); // if (newObject.printerId == 0) // { // newObject.createDate = DateTime.Now; // newObject.updateDate = DateTime.Now; // newObject.updateUserId = newObject.createUserId; // locationEntity.Add(newObject); // entity.SaveChanges(); // message = newObject.printerId.ToString(); // } // else // { // var tmpObject = entity.printers.Where(p => p.printerId == newObject.printerId).FirstOrDefault(); // tmpObject.updateDate = DateTime.Now; // tmpObject.updateUserId = newObject.updateUserId; // tmpObject.name = newObject.name; // // tmpObject.printerId = newObject.printerId; // tmpObject.printFor = newObject.printFor; // entity.SaveChanges(); // message = tmpObject.printerId.ToString(); // } // // entity.SaveChanges(); // } // } // catch // { // message = "-1"; // } //} //return message; }
public string Save(string token) { token = TokenManager.readToken(HttpContext.Current.Request); var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string message = ""; string newObject = ""; int inventoryId = 0; List <InventoryItemLocationModel> Object = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemObject") { newObject = c.Value.Replace("\\", string.Empty); newObject = newObject.Trim('"'); Object = JsonConvert.DeserializeObject <List <InventoryItemLocationModel> >(newObject, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None }); } else if (c.Type == "inventoryId") { inventoryId = int.Parse(c.Value); } } using (incposdbEntities entity = new incposdbEntities()) { List <inventoryItemLocation> items = entity.inventoryItemLocation.Where(x => x.inventoryId == inventoryId).ToList(); if (items == null || items.Count == 0)// add first time { foreach (InventoryItemLocationModel il in Object) { inventoryItemLocation tmp = new inventoryItemLocation(); if (il.createUserId == 0 || il.createUserId == null) { Nullable <int> id = null; tmp.createUserId = id; } if (il.amountDestroyed == 0 || il.amountDestroyed == null) { Nullable <int> id = 0; tmp.amountDestroyed = id; } tmp.inventoryId = inventoryId; tmp.amount = il.amount; tmp.amountDestroyed = il.amountDestroyed; tmp.isDestroyed = il.isDestroyed; tmp.isFalls = il.isFalls; tmp.realAmount = il.quantity; tmp.cause = il.cause; tmp.notes = il.notes; tmp.itemLocationId = il.itemLocationId; tmp.createDate = DateTime.Now; tmp.updateDate = DateTime.Now; tmp.updateUserId = il.createUserId; entity.inventoryItemLocation.Add(tmp); message = tmp.id.ToString(); } entity.SaveChanges(); return(TokenManager.GenerateToken(message)); } else // edit saved inventory details { foreach (InventoryItemLocationModel il in Object) { inventoryItemLocation invItem = entity.inventoryItemLocation.Find(il.id); invItem.amount = il.amount; invItem.isDestroyed = il.isDestroyed; invItem.isFalls = il.isFalls; invItem.amountDestroyed = il.amountDestroyed; invItem.cause = il.cause; invItem.notes = il.notes; invItem.updateDate = DateTime.Now; invItem.updateUserId = il.updateUserId; message = invItem.id.ToString(); } entity.SaveChanges(); return(TokenManager.GenerateToken(message)); } } message = "0"; return(TokenManager.GenerateToken(message)); } }
public string setPosConfiguration(string token) { token = TokenManager.readToken(HttpContext.Current.Request); var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string activationCode = ""; string deviceCode = ""; int posId = 0; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "activationCode") { activationCode = c.Value; } else if (c.Type == "deviceCode") { deviceCode = c.Value; } else if (c.Type == "posId") { posId = int.Parse(c.Value); } } try { using (incposdbEntities entity = new incposdbEntities()) { pos tmpPos = new pos(); var unitEntity = entity.Set <pos>(); var validSerial = entity.posSerials.Where(x => x.posSerial == activationCode).FirstOrDefault(); if (validSerial != null) // activation code is correct { var serialExist = entity.posSetting.Where(x => x.posSerialId == validSerial.id).FirstOrDefault(); if (serialExist == null) // activation code is available or unlimited package { #region add pos settings record var posSett = new posSetting() { posId = posId, posSerialId = validSerial.id, posDeviceCode = deviceCode, createDate = DateTime.Now, updateDate = DateTime.Now, }; entity.posSetting.Add(posSett); #endregion entity.SaveChanges(); return(TokenManager.GenerateToken(posId.ToString())); } else { return(TokenManager.GenerateToken("-3")); // activation code is unavailable } } else { return(TokenManager.GenerateToken("-2")); // serial is wrong } } } catch { return(TokenManager.GenerateToken("0")); } } }
public string setConfiguration(string token) { token = TokenManager.readToken(HttpContext.Current.Request); var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string setObject = ""; string activationCode = ""; string deviceCode = ""; int countryId = 0; string userName = ""; string password = ""; string branchName = ""; string branchCode = ""; string branchMobile = ""; string posName = ""; List <setValuesModel> newObject = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "setValues") { setObject = c.Value.Replace("\\", string.Empty); setObject = setObject.Trim('"'); newObject = JsonConvert.DeserializeObject <List <setValuesModel> >(setObject, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); } else if (c.Type == "activationCode") { activationCode = c.Value; } else if (c.Type == "deviceCode") { deviceCode = c.Value; } else if (c.Type == "countryId") { countryId = int.Parse(c.Value); } else if (c.Type == "userName") { userName = c.Value; } else if (c.Type == "password") { password = c.Value; } else if (c.Type == "branchMobile") { branchMobile = c.Value; } else if (c.Type == "branchName") { branchName = c.Value; } else if (c.Type == "branchCode") { branchCode = c.Value; } else if (c.Type == "posName") { posName = c.Value; } } try { using (incposdbEntities entity = new incposdbEntities()) { pos tmpPos = new pos(); var unitEntity = entity.Set <pos>(); var validSerial = entity.posSerials.Where(x => x.posSerial == activationCode).FirstOrDefault(); if (validSerial != null) // activation code is correct { var serialExist = entity.posSetting.Where(x => x.posSerialId == validSerial.id).FirstOrDefault(); if (serialExist == null) // activation code is available { var pos = entity.pos.Find(1); pos.name = posName; entity.SaveChanges(); #region add pos settings record var posSett = new posSetting() { posId = pos.posId, posSerialId = validSerial.id, posDeviceCode = deviceCode, createDate = DateTime.Now, updateDate = DateTime.Now, }; entity.posSetting.Add(posSett); #endregion #region region settings List <countriesCodes> objectlist = entity.countriesCodes.Where(x => x.isDefault == 1).ToList(); if (objectlist.Count > 0) { for (int i = 0; i < objectlist.Count; i++) { objectlist[i].isDefault = 0; } } // set is selected to isdefault=1 countriesCodes objectrow = entity.countriesCodes.Find(countryId); if (objectrow != null) { objectrow.isDefault = 1; } #endregion #region update user var user = entity.users.Find(2); user.username = userName; user.password = password; #endregion #region update branch var branch = entity.branches.Find(2); branch.name = branchName; branch.code = branchCode; branch.mobile = branchMobile; #endregion #region company info foreach (setValuesModel v in newObject) { var setId = entity.setting.Where(x => x.name == v.name).Select(x => x.settingId).Single(); var setValue = entity.setValues.Where(x => x.settingId == setId).FirstOrDefault(); setValue.value = v.value; } #endregion entity.SaveChanges(); return(TokenManager.GenerateToken(pos.posId.ToString())); } else { return(TokenManager.GenerateToken("-3")); // activation code is unavailable } } else { return(TokenManager.GenerateToken("-2")); // serial is wrong } } } catch { return(TokenManager.GenerateToken("0")); } } }
public string updateBoxState(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { int posId = 0; int userId = 0; string boxState = ""; string cashObject = ""; int isAdminClose = 0; cashTransfer cashTransfer = new cashTransfer(); CashTransferController cc = new CashTransferController(); IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "posId") { posId = int.Parse(c.Value); } else if (c.Type == "userId") { userId = int.Parse(c.Value); } else if (c.Type == "isAdminClose") { isAdminClose = int.Parse(c.Value); } else if (c.Type == "state") { boxState = c.Value; } if (c.Type == "cashTransfer") { cashObject = c.Value.Replace("\\", string.Empty); cashObject = cashObject.Trim('"'); cashTransfer = JsonConvert.DeserializeObject <cashTransfer>(cashObject, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } using (incposdbEntities entity = new incposdbEntities()) { pos pos = entity.pos.Find(posId); pos.boxState = boxState; pos.isAdminClose = (byte)isAdminClose; pos.updateUserId = userId; pos.updateDate = DateTime.Now; message = entity.SaveChanges().ToString(); cc.addCashTransfer(cashTransfer); return(TokenManager.GenerateToken(message)); } } }
public string Save(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string posObject = ""; pos newObject = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemObject") { posObject = c.Value.Replace("\\", string.Empty); posObject = posObject.Trim('"'); newObject = JsonConvert.DeserializeObject <pos>(posObject, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } if (newObject.updateUserId == 0 || newObject.updateUserId == null) { Nullable <int> id = null; newObject.updateUserId = id; } if (newObject.createUserId == 0 || newObject.createUserId == null) { Nullable <int> id = null; newObject.createUserId = id; } try { using (incposdbEntities entity = new incposdbEntities()) { pos tmpPos = new pos(); var unitEntity = entity.Set <pos>(); if (newObject.posId == 0) { ProgramInfo programInfo = new ProgramInfo(); int posMaxCount = programInfo.getPosCount(); int posCount = entity.pos.Count(); if (posCount >= posMaxCount && posMaxCount != -1) { message = "-1"; return(TokenManager.GenerateToken(message)); } else { newObject.createDate = DateTime.Now; newObject.updateDate = DateTime.Now; newObject.updateUserId = newObject.createUserId; newObject.balance = 0; newObject.balanceAll = 0; newObject.boxState = "c"; newObject.isAdminClose = 0; tmpPos = unitEntity.Add(newObject); entity.SaveChanges(); message = tmpPos.posId.ToString(); } return(TokenManager.GenerateToken(message)); } else { tmpPos = entity.pos.Where(p => p.posId == newObject.posId).FirstOrDefault(); tmpPos.name = newObject.name; tmpPos.code = newObject.code; tmpPos.branchId = newObject.branchId; tmpPos.note = newObject.note; tmpPos.updateDate = DateTime.Now; tmpPos.updateUserId = newObject.updateUserId; tmpPos.isActive = newObject.isActive; tmpPos.balance = newObject.balance; tmpPos.balanceAll = newObject.balanceAll; entity.SaveChanges(); message = tmpPos.posId.ToString(); return(TokenManager.GenerateToken(message)); } } } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } }
public string Save(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string userObject = ""; users userObj = null; users newObject = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemObject") { userObject = c.Value.Replace("\\", string.Empty); userObject = userObject.Trim('"'); newObject = JsonConvert.DeserializeObject <users>(userObject, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None }); break; } } if (newObject.updateUserId == 0 || newObject.updateUserId == null) { Nullable <int> id = null; newObject.updateUserId = id; } if (newObject.createUserId == 0 || newObject.createUserId == null) { Nullable <int> id = null; newObject.createUserId = id; } try { using (incposdbEntities entity = new incposdbEntities()) { var userEntity = entity.Set <users>(); var catEntity = entity.Set <categoryuser>(); if (newObject.userId == 0) { newObject.isAdmin = false; ProgramInfo programInfo = new ProgramInfo(); int userMaxCount = programInfo.getUserCount(); int usersCount = entity.users.Count(); if (usersCount >= userMaxCount && userMaxCount != -1) { message = "-1"; return(TokenManager.GenerateToken(message)); } else { newObject.createDate = DateTime.Now; newObject.updateDate = DateTime.Now; newObject.updateUserId = newObject.createUserId; newObject.balance = 0; newObject.balanceType = 0; userObj = userEntity.Add(newObject); // get all categories var categories = entity.categories.Where(x => x.isActive == 1).Select(x => x.categoryId).ToList(); int sequence = 0; for (int i = 0; i < categories.Count; i++) { sequence++; int categoryId = categories[i]; categoryuser cu = new categoryuser() { categoryId = categoryId, userId = userObj.userId, sequence = sequence, createDate = DateTime.Now, updateDate = DateTime.Now, createUserId = newObject.createUserId, updateUserId = newObject.updateUserId, }; catEntity.Add(cu); } entity.SaveChanges().ToString(); message = userObj.userId.ToString(); return(TokenManager.GenerateToken(message)); } } else { userObj = entity.users.Where(p => p.userId == newObject.userId).FirstOrDefault(); userObj.name = newObject.name; userObj.username = newObject.username; userObj.password = newObject.password; userObj.name = newObject.name; userObj.lastname = newObject.lastname; userObj.job = newObject.job; userObj.workHours = newObject.workHours; userObj.updateDate = DateTime.Now; userObj.updateUserId = newObject.updateUserId; userObj.phone = newObject.phone; userObj.mobile = newObject.mobile; userObj.email = newObject.email; userObj.notes = newObject.notes; userObj.address = newObject.address; userObj.isActive = newObject.isActive; userObj.balance = newObject.balance; userObj.balanceType = newObject.balanceType; userObj.isOnline = newObject.isOnline; entity.SaveChanges().ToString(); message = userObj.userId.ToString(); return(TokenManager.GenerateToken(message)); } } } catch { message = "0"; return(TokenManager.GenerateToken(message)); // return TokenManager.GenerateToken(ex.ToString()); } } }
public string Delete(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { int agentId = 0; int userId = 0; Boolean final = false; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemId") { agentId = int.Parse(c.Value); } else if (c.Type == "userId") { userId = int.Parse(c.Value); } else if (c.Type == "final") { final = bool.Parse(c.Value); } } if (!final) { try { using (incposdbEntities entity = new incposdbEntities()) { var tmpAgent = entity.agents.Where(p => p.agentId == agentId).First(); tmpAgent.isActive = 0; tmpAgent.updateDate = DateTime.Now; tmpAgent.updateUserId = userId; message = entity.SaveChanges().ToString(); } return(TokenManager.GenerateToken(message)); } catch { return(TokenManager.GenerateToken("0")); } } else { try { using (incposdbEntities entity = new incposdbEntities()) { var tmpAgent = entity.agents.Where(p => p.agentId == agentId).First(); entity.agents.Remove(tmpAgent); message = entity.SaveChanges().ToString(); } return(TokenManager.GenerateToken(message)); } catch { return(TokenManager.GenerateToken("0")); } } } }
public string Delete(string token) { //int objectId, int userId, bool final string message = ""; token = TokenManager.readToken(HttpContext.Current.Request); var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { int objectId = 0; int userId = 0; bool final = false; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "objectId") { objectId = int.Parse(c.Value); } else if (c.Type == "userId") { userId = int.Parse(c.Value); } else if (c.Type == "final") { final = bool.Parse(c.Value); } } if (final) { try { using (incposdbEntities entity = new incposdbEntities()) { objects Deleterow = entity.objects.Find(objectId); entity.objects.Remove(Deleterow); message = entity.SaveChanges().ToString(); // return Ok("OK"); return(TokenManager.GenerateToken(message)); // return Ok("OK"); } } catch { return(TokenManager.GenerateToken("0")); } } else { try { using (incposdbEntities entity = new incposdbEntities()) { objects Obj = entity.objects.Find(objectId); Obj.isActive = 0; Obj.updateUserId = userId; Obj.updateDate = DateTime.Now; message = entity.SaveChanges().ToString(); // return Ok("OK"); return(TokenManager.GenerateToken(message)); } } catch { return(TokenManager.GenerateToken("0")); } } } //var re = Request; //var headers = re.Headers; //string token = ""; //if (headers.Contains("APIKey")) //{ // token = headers.GetValues("APIKey").First(); //} //Validation validation = new Validation(); //bool valid = validation.CheckApiKey(token); //if (valid) //{ // if (final) // { // try // { // using (incposdbEntities entity = new incposdbEntities()) // { // objects Deleterow = entity.objects.Find(objectId); // entity.objects.Remove(Deleterow); // entity.SaveChanges(); // return Ok("OK"); // } // } // catch // { // return NotFound(); // } // } // else // { // try // { // using (incposdbEntities entity = new incposdbEntities()) // { // objects Obj = entity.objects.Find(objectId); // Obj.isActive = 0; // Obj.updateUserId = userId; // Obj.updateDate = DateTime.Now; // entity.SaveChanges(); // return Ok("Ok"); // } // } // catch // { // return NotFound(); // } // } //} //else // return NotFound(); }
public string setAsRead(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { try { int notUserId = 0; int posId = 0; string type = ""; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "notUserId") { notUserId = int.Parse(c.Value); } else if (c.Type == "posId") { posId = int.Parse(c.Value); } else if (c.Type == "type") { type = c.Value; } } using (incposdbEntities entity = new incposdbEntities()) { // var notEntity = entity.Set<notificationUser>(); var List = (from S in entity.notificationUser where ((S.userId == notUserId || S.posId == posId) && S.isRead == false && S.notification.msgType.Contains(type)) select new NotificationUserModel() { notUserId = S.notUserId, notId = S.notId, userId = S.userId, posId = S.posId, isRead = S.isRead, createUserId = S.createUserId, updateUserId = S.updateUserId, createDate = S.createDate, updateDate = S.updateDate, title = S.notification.title, ncontent = S.notification.ncontent, path = S.notification.path, msgType = S.notification.msgType, side = S.notification.side, }).ToList(); //List.ForEach(a => a.isRead = true ); //List.ForEach(a => a.updateDate = DateTime.Now); foreach (NotificationUserModel m in List) { var notEntity = entity.notificationUser.Find(m.notUserId); notEntity.isRead = true; notEntity.updateDate = DateTime.Now; entity.SaveChanges(); } message = "1"; return(TokenManager.GenerateToken(message)); } } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } }
public string Delete(string token) {//int printerId string message = ""; token = TokenManager.readToken(HttpContext.Current.Request); var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { int printerId = 0; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "printerId") { printerId = int.Parse(c.Value); } } try { using (incposdbEntities entity = new incposdbEntities()) { printers objectDelete = entity.printers.Find(printerId); entity.printers.Remove(objectDelete); message = entity.SaveChanges().ToString(); } return(TokenManager.GenerateToken(message)); } catch { return(TokenManager.GenerateToken("0")); } } //var re = Request; // //string token = ""; //int message = 0; //if (headers.Contains("APIKey")) //{ // token = headers.GetValues("APIKey").First(); //} //Validation validation = new Validation(); //bool valid = validation.CheckApiKey(token); //if (valid) //{ // try // { // using (incposdbEntities entity = new incposdbEntities()) // { // printers objectDelete = entity.printers.Find(printerId); // entity.printers.Remove(objectDelete); // message = entity.SaveChanges(); // return message.ToString(); // } // } // catch // { // return "-1"; // } //} //else // return "-3"; }
public string Save(string token) { token = TokenManager.readToken(HttpContext.Current.Request); string message = ""; var strP = TokenManager.GetPrincipal(token); if (strP != "0") //invalid authorization { return(TokenManager.GenerateToken(strP)); } else { string agentObject = ""; agents agentObj = null; IEnumerable <Claim> claims = TokenManager.getTokenClaims(token); foreach (Claim c in claims) { if (c.Type == "itemObject") { agentObject = c.Value.Replace("\\", string.Empty); agentObject = agentObject.Trim('"'); agentObj = JsonConvert.DeserializeObject <agents>(agentObject, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } try { agents agent; using (incposdbEntities entity = new incposdbEntities()) { var agentEntity = entity.Set <agents>(); if (agentObj.agentId == 0) { ProgramInfo programInfo = new ProgramInfo(); int agentMaxCount = 0; if (agentObj.type == "c") { agentMaxCount = programInfo.getCustomerCount(); } else if (agentObj.type == "v") { agentMaxCount = programInfo.getVendorCount(); } int agentCount = entity.agents.Where(x => x.type == agentObj.type).Count(); if (agentCount >= agentMaxCount && agentMaxCount != -1) { message = "-1"; return(TokenManager.GenerateToken(message)); } else { agentObj.createDate = DateTime.Now; agentObj.updateDate = DateTime.Now; agentObj.updateUserId = agentObj.createUserId; agentObj.balanceType = 0; agent = agentEntity.Add(agentObj); } } else { agent = entity.agents.Where(p => p.agentId == agentObj.agentId).First(); agent.accType = agentObj.accType; agent.address = agentObj.address; agent.code = agentObj.code; agent.company = agentObj.company; agent.email = agentObj.email; agent.image = agentObj.image; agent.mobile = agentObj.mobile; agent.name = agentObj.name; agent.notes = agentObj.notes; agent.phone = agentObj.phone; agent.type = agentObj.type; agent.maxDeserve = agentObj.maxDeserve; agent.fax = agentObj.fax; agent.updateDate = DateTime.Now;// server current date agent.updateUserId = agentObj.updateUserId; agent.isActive = agentObj.isActive; agent.balance = agentObj.balance; agent.balanceType = agentObj.balanceType; agent.isLimited = agentObj.isLimited; agent.payType = agentObj.payType; } entity.SaveChanges(); message = agent.agentId.ToString(); } return(TokenManager.GenerateToken(message)); } catch { message = "0"; return(TokenManager.GenerateToken(message)); } } }