コード例 #1
0
        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));
        }
コード例 #2
0
        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));
                }
            }
        }
コード例 #3
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              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));
                }
            }
        }
コード例 #4
0
        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));
                }
            }
        }
コード例 #5
0
        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));
                }
            }
        }
コード例 #6
0
        public string UpdateBranchByUserId(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 branchesUsersObject      = "";
                List <branchesUsers> newListObj = null;
                int userId                 = 0;
                int updateUserId           = 0;
                IEnumerable <Claim> claims = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "newList")
                    {
                        branchesUsersObject = c.Value.Replace("\\", string.Empty);
                        branchesUsersObject = branchesUsersObject.Trim('"');
                        newListObj          = JsonConvert.DeserializeObject <List <branchesUsers> >(branchesUsersObject, new IsoDateTimeConverter {
                            DateTimeFormat = "dd/MM/yyyy"
                        });
                    }
                    else if (c.Type == "userId")
                    {
                        userId = int.Parse(c.Value);
                    }
                    else
                    if (c.Type == "updateUserId")
                    {
                        updateUserId = int.Parse(c.Value);
                    }
                }
                List <branchesUsers> items = null;
                // delete old invoice items
                using (incposdbEntities entity = new incposdbEntities())
                {
                    items = entity.branchesUsers.Where(x => x.userId == userId).ToList();
                    if (items != null)
                    {
                        entity.branchesUsers.RemoveRange(items);
                        try
                        { entity.SaveChanges(); }
                        catch (Exception ex)
                        {
                            message = "-2";
                            return(TokenManager.GenerateToken(message));
                        }
                    }
                }
                using (incposdbEntities entity = new incposdbEntities())
                {
                    for (int i = 0; i < newListObj.Count; i++)
                    {
                        if (newListObj[i].updateUserId == 0 || newListObj[i].updateUserId == null)
                        {
                            Nullable <int> id = null;
                            newListObj[i].updateUserId = id;
                        }
                        if (newListObj[i].createUserId == 0 || newListObj[i].createUserId == null)
                        {
                            Nullable <int> id = null;
                            newListObj[i].createUserId = id;
                        }
                        if (newListObj[i].branchId == 0 || newListObj[i].branchId == null)
                        {
                            Nullable <int> id = null;
                            newListObj[i].branchId = id;
                        }
                        if (newListObj[i].userId == 0 || newListObj[i].userId == null)
                        {
                            Nullable <int> id = null;
                            newListObj[i].userId = id;
                        }
                        var branchEntity = entity.Set <branchesUsers>();

                        newListObj[i].createDate   = DateTime.Now;
                        newListObj[i].updateDate   = DateTime.Now;
                        newListObj[i].updateUserId = updateUserId;
                        newListObj[i].userId       = userId;
                        branchEntity.Add(newListObj[i]);
                        entity.SaveChanges();
                    }
                    try
                    {
                        entity.SaveChanges().ToString();
                        message = "1";
                        return(TokenManager.GenerateToken(message));
                    }
                    catch
                    {
                        message = "0";
                        return(TokenManager.GenerateToken(message));
                    }
                }
            }
        }
コード例 #7
0
        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;
        }
コード例 #8
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;
        }
コード例 #9
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"));
                }
            }
        }
コード例 #10
0
        public string Save(string Object)
        {
            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('"');
                memberships newObject = JsonConvert.DeserializeObject <memberships>(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 <memberships>();
                        if (newObject.membershipId == 0)
                        {
                            newObject.createDate   = DateTime.Now;
                            newObject.updateDate   = DateTime.Now;
                            newObject.updateUserId = newObject.createUserId;


                            locationEntity.Add(newObject);
                            entity.SaveChanges();
                            message = newObject.membershipId.ToString();
                        }
                        else
                        {
                            var tmpObject = entity.memberships.Where(p => p.membershipId == newObject.membershipId).FirstOrDefault();

                            tmpObject.updateDate   = DateTime.Now;
                            tmpObject.updateUserId = newObject.updateUserId;

                            tmpObject.name = newObject.name;

                            tmpObject.notes                = newObject.notes;
                            tmpObject.isActive             = newObject.isActive;
                            tmpObject.deliveryDiscount     = newObject.deliveryDiscount;
                            tmpObject.deliveryDiscountType = newObject.deliveryDiscountType;
                            tmpObject.invoiceDiscount      = newObject.invoiceDiscount;
                            tmpObject.invoiceDiscountType  = newObject.invoiceDiscountType;


                            entity.SaveChanges();

                            message = tmpObject.membershipId.ToString();
                        }
                        //  entity.SaveChanges();
                    }
                }
                catch
                {
                    message = "-1";
                }
            }
            return(message);
        }
コード例 #11
0
        public string Save(string token)
        {
            string message = "";

            token = TokenManager.readToken(HttpContext.Current.Request);
            var strP = TokenManager.GetPrincipal(token);

            if (strP != "0") //invalid authorization
            {
                return(TokenManager.GenerateToken(strP));
            }
            else
            {
                int    invoiceId = 0;
                string Object    = "";
                List <itemsTransfer> newObject = new List <itemsTransfer>();
                IEnumerable <Claim>  claims    = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "itemTransferObject")
                    {
                        Object    = c.Value.Replace("\\", string.Empty);
                        Object    = Object.Trim('"');
                        newObject = JsonConvert.DeserializeObject <List <itemsTransfer> >(Object, new IsoDateTimeConverter {
                            DateTimeFormat = "dd/MM/yyyy"
                        });
                    }
                    else if (c.Type == "invoiceId")
                    {
                        invoiceId = int.Parse(c.Value);
                    }
                }
                if (newObject != null)
                {
                    try
                    {
                        // delete old invoice items
                        using (incposdbEntities entity = new incposdbEntities())
                        {
                            //List<invoiceOrder> iol = entity.invoiceOrder.Where(x => x.invoiceId == invoiceId).ToList();
                            //entity.invoiceOrder.RemoveRange(iol);
                            //entity.SaveChanges();

                            List <itemsTransfer> items = entity.itemsTransfer.Where(x => x.invoiceId == invoiceId).ToList();
                            entity.itemsTransfer.RemoveRange(items);
                            entity.SaveChanges();

                            var invoice = entity.invoices.Find(invoiceId);
                            for (int i = 0; i < newObject.Count; i++)
                            {
                                itemsTransfer t;
                                if (newObject[i].createUserId == 0 || newObject[i].createUserId == null)
                                {
                                    Nullable <int> id = null;
                                    newObject[i].createUserId = id;
                                }
                                if (newObject[i].offerId == 0)
                                {
                                    Nullable <int> id = null;
                                    newObject[i].offerId = id;
                                }
                                if (newObject[i].itemSerial == null)
                                {
                                    newObject[i].itemSerial = "";
                                }

                                var transferEntity = entity.Set <itemsTransfer>();

                                newObject[i].invoiceId    = invoiceId;
                                newObject[i].createDate   = DateTime.Now;
                                newObject[i].updateDate   = DateTime.Now;
                                newObject[i].updateUserId = newObject[i].createUserId;

                                t = entity.itemsTransfer.Add(newObject[i]);
                                entity.SaveChanges();

                                //if (orderId != 0)
                                //{
                                //    invoiceOrder invoiceOrder = new invoiceOrder()
                                //    {
                                //        invoiceId = invoiceId,
                                //        orderId = orderId,
                                //        quantity = (int)newObject[i].quantity,
                                //        itemsTransferId = t.itemsTransId,
                                //    };
                                //    entity.invoiceOrder.Add(invoiceOrder);
                                //}
                                if (newObject[i].offerId != null && invoice.invType == "s")
                                {
                                    int offerId    = (int)newObject[i].offerId;
                                    int itemUnitId = (int)newObject[i].itemUnitId;
                                    var offer      = entity.itemsOffers.Where(x => x.iuId == itemUnitId && x.offerId == offerId).FirstOrDefault();

                                    offer.used += (int)newObject[i].quantity;
                                }
                            }
                            entity.SaveChanges();
                            message = "1";
                            return(TokenManager.GenerateToken(message));
                        }
                    }
                    catch
                    {
                        message = "0";
                        return(TokenManager.GenerateToken(message));
                    }
                }
                else
                {
                    return(TokenManager.GenerateToken("0"));
                }
            }
        }
コード例 #12
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 offerObject         = "";
                offers newObject           = null;
                IEnumerable <Claim> claims = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "itemObject")
                    {
                        offerObject = c.Value.Replace("\\", string.Empty);
                        offerObject = offerObject.Trim('"');
                        newObject   = JsonConvert.DeserializeObject <offers>(offerObject, 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())
                    {
                        offers oldObject   = new offers();
                        var    offerEntity = entity.Set <offers>();
                        if (newObject.offerId == 0)
                        {
                            newObject.updateDate = newObject.createDate;
                            oldObject            = offerEntity.Add(newObject);
                            entity.SaveChanges();
                            message = oldObject.offerId.ToString();
                            return(TokenManager.GenerateToken(message));
                        }
                        else
                        {
                            oldObject               = entity.offers.Where(p => p.offerId == newObject.offerId).FirstOrDefault();
                            oldObject.name          = newObject.name;
                            oldObject.code          = newObject.code;
                            oldObject.discountType  = newObject.discountType;
                            oldObject.discountValue = newObject.discountValue;
                            oldObject.startDate     = newObject.startDate;
                            oldObject.endDate       = newObject.endDate;
                            oldObject.updateDate    = newObject.updateDate;
                            oldObject.updateUserId  = newObject.updateUserId;
                            oldObject.notes         = newObject.notes;
                            oldObject.isActive      = newObject.isActive;
                            entity.SaveChanges();
                            message = oldObject.offerId.ToString();
                            return(TokenManager.GenerateToken(message));
                        }
                    }
                }
                catch
                {
                    message = "0";
                }
            }
            return(TokenManager.GenerateToken(message));
        }
コード例 #13
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 bankId              = "";
                banks  newObject           = null;
                IEnumerable <Claim> claims = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "itemObject")
                    {
                        bankId    = c.Value.Replace("\\", string.Empty);
                        bankId    = bankId.Trim('"');
                        newObject = JsonConvert.DeserializeObject <banks>(bankId, 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())
                    {
                        banks tmpBank    = new banks();
                        var   bankEntity = entity.Set <banks>();
                        if (newObject.bankId == 0)
                        {
                            newObject.createDate   = DateTime.Now;
                            newObject.updateDate   = DateTime.Now;
                            newObject.updateUserId = newObject.createUserId;
                            tmpBank = bankEntity.Add(newObject);
                            entity.SaveChanges();
                            message = tmpBank.bankId.ToString();;
                        }
                        else
                        {
                            tmpBank              = entity.banks.Where(p => p.bankId == newObject.bankId).FirstOrDefault();
                            tmpBank.name         = newObject.name;
                            tmpBank.accNumber    = newObject.accNumber;
                            tmpBank.address      = newObject.address;
                            tmpBank.mobile       = newObject.mobile;
                            tmpBank.notes        = newObject.notes;
                            tmpBank.phone        = newObject.phone;
                            tmpBank.updateDate   = DateTime.Now;
                            tmpBank.updateUserId = newObject.updateUserId;
                            tmpBank.isActive     = newObject.isActive;
                            entity.SaveChanges();
                            message = tmpBank.bankId.ToString();
                        }
                        return(TokenManager.GenerateToken(message));
                    }
                }

                catch
                {
                    message = "0";
                    return(TokenManager.GenerateToken(message));
                }
            }
        }
コード例 #14
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 Object              = "";
                error  newObject           = null;
                IEnumerable <Claim> claims = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "itemObject")
                    {
                        Object    = c.Value.Replace("\\", string.Empty);
                        Object    = Object.Trim('"');
                        newObject = JsonConvert.DeserializeObject <error>(Object, new IsoDateTimeConverter {
                            DateTimeFormat = "dd/MM/yyyy"
                        });
                        break;
                    }
                }

                if (newObject.createUserId == 0 || newObject.createUserId == null)
                {
                    Nullable <int> id = null;
                    newObject.createUserId = id;
                }
                if (newObject.posId == 0 || newObject.posId == null)
                {
                    Nullable <int> posId = null;
                    newObject.posId = posId;
                }
                if (newObject.branchId == 0 || newObject.branchId == null)
                {
                    Nullable <int> branchId = null;
                    newObject.branchId = branchId;
                }
                try
                {
                    using (incposdbEntities entity = new incposdbEntities())
                    {
                        var locationEntity = entity.Set <error>();
                        if (newObject.errorId == 0)
                        {
                            newObject.createDate = DateTime.Now;
                            locationEntity.Add(newObject);
                            entity.SaveChanges();
                            message = newObject.errorId.ToString();
                            return(TokenManager.GenerateToken(message));
                        }
                        else
                        {
                            var tmpObject = entity.error.Where(p => p.errorId == newObject.errorId).FirstOrDefault();

                            // newObject.createDate = DateTime.Now;

                            tmpObject.num        = newObject.num;
                            tmpObject.msg        = newObject.msg;
                            tmpObject.stackTrace = newObject.stackTrace;
                            tmpObject.targetSite = newObject.targetSite;
                            tmpObject.posId      = newObject.posId;
                            tmpObject.branchId   = newObject.branchId;

                            tmpObject.createUserId = newObject.createUserId;


                            entity.SaveChanges();

                            message = tmpObject.errorId.ToString();
                            return(TokenManager.GenerateToken(message));
                        }
                    }
                }
                catch
                {
                    message = "0";
                    return(TokenManager.GenerateToken(message));
                }
            }
        }
コード例 #15
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              obj        = "";
                int                 branchId   = 0;
                string              objectName = "";
                string              prefix     = "";
                int                 userId     = 0;
                int                 posId      = 0;
                notification        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 <notification>(obj, new IsoDateTimeConverter {
                            DateTimeFormat = "dd/MM/yyyy"
                        });
                        //break;
                    }
                    else if (c.Type == "branchId")
                    {
                        branchId = int.Parse(c.Value);
                    }
                    else if (c.Type == "objectName")
                    {
                        objectName = c.Value;
                    }
                    else if (c.Type == "prefix")
                    {
                        prefix = c.Value;
                    }
                    else if (c.Type == "userId")
                    {
                        userId = int.Parse(c.Value);
                    }
                    else if (c.Type == "posId")
                    {
                        posId = int.Parse(c.Value);
                    }
                }
                try
                {
                    using (incposdbEntities entity = new incposdbEntities())
                    {
                        Object.ncontent   = prefix + ":" + Object.ncontent;
                        Object.isActive   = 1;
                        Object.createDate = DateTime.Now;
                        Object.updateDate = DateTime.Now;

                        var          notEntity = entity.Set <notification>();
                        notification not       = notEntity.Add(Object);
                        entity.SaveChanges();

                        #region pos notifications
                        if (posId != 0)
                        {
                            var notUserEntity        = entity.Set <notificationUser>();
                            notificationUser notUser = new notificationUser()
                            {
                                notId        = not.notId,
                                posId        = posId,
                                isRead       = false,
                                createDate   = DateTime.Now,
                                updateDate   = DateTime.Now,
                                createUserId = Object.createUserId,
                                updateUserId = Object.createUserId,
                            };
                            notUserEntity.Add(notUser);
                        }
                        #endregion
                        else if (userId == 0)
                        {
                            var users = (from u in entity.users.Where(x => x.isActive == 1)
                                         join b in entity.branchesUsers on u.userId equals b.userId
                                         where b.branchId == branchId
                                         select new UserModel()
                            {
                                userId = u.userId
                            }
                                         ).ToList();

                            foreach (UserModel user in users)
                            {
                                var groupObjects = (from GO in entity.groupObject
                                                    join U in entity.users on GO.groupId equals U.groupId
                                                    join G in entity.groups on GO.groupId equals G.groupId
                                                    join O in entity.objects on GO.objectId equals O.objectId
                                                    join POO in entity.objects on O.parentObjectId equals POO.objectId into JP

                                                    from PO in JP.DefaultIfEmpty()
                                                    where U.userId == user.userId
                                                    select new
                                {
                                    //group object
                                    GO.id,
                                    GO.groupId,
                                    GO.objectId,
                                    GO.addOb,
                                    GO.updateOb,
                                    GO.deleteOb,
                                    GO.showOb,
                                    GO.reportOb,
                                    GO.levelOb,
                                    //group
                                    GroupName = G.name,
                                    //object
                                    ObjectName = O.name,
                                    O.parentObjectId,
                                    O.objectType,
                                    parentObjectName = PO.name,
                                }).ToList();

                                var element = groupObjects.Where(X => X.ObjectName == objectName).FirstOrDefault();
                                if (element.showOb == 1)
                                {
                                    // add notification to users
                                    var notUserEntity        = entity.Set <notificationUser>();
                                    notificationUser notUser = new notificationUser()
                                    {
                                        notId        = not.notId,
                                        userId       = user.userId,
                                        isRead       = false,
                                        createDate   = DateTime.Now,
                                        updateDate   = DateTime.Now,
                                        createUserId = Object.createUserId,
                                        updateUserId = Object.createUserId,
                                    };
                                    notUserEntity.Add(notUser);
                                }
                            }
                        }
                        else // add notification to one user whose id = userId
                        {
                            var notUserEntity        = entity.Set <notificationUser>();
                            notificationUser notUser = new notificationUser()
                            {
                                notId        = not.notId,
                                userId       = userId,
                                isRead       = false,
                                createDate   = DateTime.Now,
                                updateDate   = DateTime.Now,
                                createUserId = Object.createUserId,
                                updateUserId = Object.createUserId,
                            };
                            notUserEntity.Add(notUser);
                        }
                        entity.SaveChanges();
                    }
                    message = "1";
                    return(TokenManager.GenerateToken(message));
                }
                catch
                {
                    message = "0";
                    return(TokenManager.GenerateToken(message));
                }
            }
        }
コード例 #16
0
        public void addNotifications(string objectName, string notificationObj, int branchId, string itemName)
        {
            notificationObj = notificationObj.Replace("\\", string.Empty);
            notificationObj = notificationObj.Trim('"');
            notification Object = JsonConvert.DeserializeObject <notification>(notificationObj, new JsonSerializerSettings {
                DateParseHandling = DateParseHandling.None
            });

            //try
            //{
            using (incposdbEntities entity = new incposdbEntities())
            {
                var users = (from u in entity.users.Where(x => x.isActive == 1 && x.isAdmin == false)
                             join b in entity.branchesUsers on u.userId equals b.userId
                             where b.branchId == branchId
                             select new UserModel()
                {
                    userId = u.userId
                }
                             ).ToList();

                Object.ncontent   = itemName + ":" + Object.ncontent;
                Object.isActive   = 1;
                Object.createDate = DateTime.Now;
                Object.updateDate = DateTime.Now;

                var          notEntity = entity.Set <notification>();
                notification not       = notEntity.Add(Object);

                entity.SaveChanges();
                notificationUser notUser;
                var notUserEntity = entity.Set <notificationUser>();
                foreach (UserModel user in users)
                {
                    var groupObjects = (from GO in entity.groupObject
                                        join U in entity.users on GO.groupId equals U.groupId
                                        join G in entity.groups on GO.groupId equals G.groupId
                                        join O in entity.objects on GO.objectId equals O.objectId
                                        join POO in entity.objects on O.parentObjectId equals POO.objectId into JP

                                        from PO in JP.DefaultIfEmpty()
                                        where U.userId == user.userId
                                        select new
                    {
                        //group object
                        GO.id,
                        GO.groupId,
                        GO.objectId,
                        GO.addOb,
                        GO.updateOb,
                        GO.deleteOb,
                        GO.showOb,
                        GO.reportOb,
                        GO.levelOb,
                        //group
                        GroupName = G.name,
                        //object
                        ObjectName = O.name,
                        O.parentObjectId,
                        O.objectType,
                        parentObjectName = PO.name,
                    }).ToList();

                    var element = groupObjects.Where(X => X.ObjectName == objectName).FirstOrDefault();
                    if (element != null)
                    {
                        if (element.showOb == 1)
                        {
                            // add notification to users
                            notUser = new notificationUser()
                            {
                                notId        = not.notId,
                                userId       = user.userId,
                                isRead       = false,
                                createDate   = DateTime.Now,
                                updateDate   = DateTime.Now,
                                createUserId = Object.createUserId,
                                updateUserId = Object.createUserId,
                            };
                            notUserEntity.Add(notUser);
                        }
                    }
                }
                var admins = (from u in entity.users.Where(x => x.isActive == 1 && x.isAdmin == true)
                              select new UserModel()
                {
                    userId = u.userId
                }
                              ).ToList();
                foreach (UserModel user in admins)
                {
                    notUser = new notificationUser()
                    {
                        notId        = not.notId,
                        userId       = user.userId,
                        isRead       = false,
                        createDate   = DateTime.Now,
                        updateDate   = DateTime.Now,
                        createUserId = Object.createUserId,
                        updateUserId = Object.createUserId,
                    };
                    notUserEntity.Add(notUser);
                }
                entity.SaveChanges();
            }
        }
コード例 #17
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 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));
                }
            }
        }
コード例 #18
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 unitObject          = "";
                units  Object              = null;
                IEnumerable <Claim> claims = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "itemObject")
                    {
                        unitObject = c.Value.Replace("\\", string.Empty);
                        unitObject = unitObject.Trim('"');
                        Object     = JsonConvert.DeserializeObject <units>(unitObject, new IsoDateTimeConverter {
                            DateTimeFormat = "dd/MM/yyyy"
                        });
                        break;
                    }
                }

                try
                {
                    using (incposdbEntities entity = new incposdbEntities())
                    {
                        units tmpUnit    = new units();
                        var   unitEntity = entity.Set <units>();
                        if (Object.unitId == 0)
                        {
                            Object.createDate   = DateTime.Now;
                            Object.updateDate   = DateTime.Now;
                            Object.updateUserId = Object.createUserId;

                            unitEntity.Add(Object);
                            tmpUnit = unitEntity.Add(Object);
                            entity.SaveChanges();
                            message = tmpUnit.unitId.ToString();
                            return(TokenManager.GenerateToken(message));
                        }
                        else
                        {
                            tmpUnit              = entity.units.Where(p => p.unitId == Object.unitId).FirstOrDefault();
                            tmpUnit.name         = Object.name;
                            tmpUnit.notes        = Object.notes;
                            tmpUnit.isSmallest   = Object.isSmallest;
                            tmpUnit.smallestId   = Object.smallestId;
                            tmpUnit.updateDate   = DateTime.Now;
                            tmpUnit.updateUserId = Object.updateUserId;
                            tmpUnit.parentid     = Object.parentid;
                            tmpUnit.isActive     = Object.isActive;
                            entity.SaveChanges();
                            message = tmpUnit.unitId.ToString();
                            return(TokenManager.GenerateToken(message));
                        }
                    }
                }

                catch
                {
                    message = "0";
                }
                return(TokenManager.GenerateToken(message));
            }
        }
コード例 #19
0
        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"));
                }
            }
        }
コード例 #20
0
        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              = "";
                bondes 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 <bondes>(Object, new IsoDateTimeConverter {
                            DateTimeFormat = "dd/MM/yyyy"
                        });
                        break;
                    }
                }
                if (newObject != null)
                {
                    bondes tmpObject = null;


                    try
                    {
                        using (incposdbEntities entity = new incposdbEntities())
                        {
                            var bondEntity = entity.Set <bondes>();
                            if (newObject.bondId == 0 || newObject.bondId == null)
                            {
                                newObject.createDate   = DateTime.Now;
                                newObject.updateDate   = DateTime.Now;
                                newObject.updateUserId = newObject.createUserId;
                                bondEntity.Add(newObject);
                                entity.SaveChanges();
                                message = newObject.bondId.ToString();
                            }
                            else
                            {
                                var tmpbond = entity.bondes.Where(p => p.bondId == newObject.bondId).FirstOrDefault();

                                tmpbond.bondId       = newObject.bondId;
                                tmpbond.number       = newObject.number;
                                tmpbond.amount       = newObject.amount;
                                tmpbond.deserveDate  = newObject.deserveDate;
                                tmpbond.type         = newObject.type;
                                tmpbond.isRecieved   = newObject.isRecieved;
                                tmpbond.notes        = newObject.notes;
                                tmpbond.createDate   = newObject.createDate;
                                tmpbond.updateDate   = DateTime.Now;// server current date;
                                tmpbond.createUserId = newObject.createUserId;
                                tmpbond.updateUserId = newObject.updateUserId;
                                tmpbond.isActive     = newObject.isActive;
                                tmpbond.cashTransId  = newObject.cashTransId;

                                //message = "card Is Updated Successfully";
                                entity.SaveChanges();
                                message = tmpbond.bondId.ToString();
                            }
                        }

                        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)
            //{
            //    bondObject = bondObject.Replace("\\", string.Empty);
            //    bondObject = bondObject.Trim('"');
            //    bondes Object = JsonConvert.DeserializeObject<bondes>(bondObject, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None });
            //    try
            //    {
            //        using (incposdbEntities entity = new incposdbEntities())
            //        {
            //            var bondEntity = entity.Set<bondes>();
            //            if (Object.bondId == 0 || Object.bondId == null)
            //            {

            //                Object.createDate = DateTime.Now;
            //                Object.updateDate = DateTime.Now;
            //                Object.updateUserId = Object.createUserId;
            //                bondEntity.Add(Object);
            //                entity.SaveChanges();
            //                message = Object.bondId.ToString();
            //            }
            //            else
            //            {

            //                var tmpbond = entity.bondes.Where(p => p.bondId == Object.bondId).FirstOrDefault();

            //                tmpbond.bondId = Object.bondId;
            //                tmpbond.number = Object.number;
            //                tmpbond.amount = Object.amount;
            //                tmpbond.deserveDate = Object.deserveDate;
            //                tmpbond.type = Object.type;
            //                tmpbond.isRecieved = Object.isRecieved;
            //                tmpbond.notes = Object.notes;
            //                tmpbond.createDate = Object.createDate;
            //                tmpbond.updateDate = DateTime.Now;// server current date;
            //                tmpbond.createUserId = Object.createUserId;
            //                tmpbond.updateUserId = Object.updateUserId;
            //                tmpbond.isActive = Object.isActive;
            //                tmpbond.cashTransId = Object.cashTransId;

            //                //message = "card Is Updated Successfully";
            //                entity.SaveChanges();
            //                message = tmpbond.bondId.ToString();

            //            }


            //        }
            //        return message;
            //    }

            //    catch
            //    {
            //        return "-1";
            //    }
            //}
            //else
            //    return "-1";
        }
コード例 #21
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 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));
                }
            }
        }
コード例 #22
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              sectionObject = "";
                sections            newObject     = null;
                IEnumerable <Claim> claims        = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "itemObject")
                    {
                        sectionObject = c.Value.Replace("\\", string.Empty);
                        sectionObject = sectionObject.Trim('"');
                        newObject     = JsonConvert.DeserializeObject <sections>(sectionObject, 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;
                }
                if (newObject.branchId == 0 || newObject.branchId == null)
                {
                    Nullable <int> id = null;
                    newObject.branchId = id;
                }
                try
                {
                    using (incposdbEntities entity = new incposdbEntities())
                    {
                        var sectionEntity = entity.Set <sections>();
                        if (newObject.sectionId == 0)
                        {
                            newObject.createDate   = DateTime.Now;
                            newObject.updateDate   = DateTime.Now;
                            newObject.updateUserId = newObject.createUserId;

                            sectionEntity.Add(newObject);
                            entity.SaveChanges();
                            message = newObject.sectionId.ToString();
                        }
                        else
                        {
                            var tmpSection = entity.sections.Where(p => p.sectionId == newObject.sectionId).FirstOrDefault();
                            tmpSection.name         = newObject.name;
                            tmpSection.branchId     = newObject.branchId;
                            tmpSection.isActive     = newObject.isActive;
                            tmpSection.isFreeZone   = newObject.isFreeZone;
                            tmpSection.note         = newObject.note;
                            tmpSection.updateDate   = DateTime.Now;
                            tmpSection.updateUserId = newObject.updateUserId;
                            entity.SaveChanges();
                            message = tmpSection.sectionId.ToString();
                        }
                    }
                }
                catch
                {
                    message = "-1";
                }
            }
            return(TokenManager.GenerateToken(message));
        }
コード例 #23
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              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));
                }
            }
        }
コード例 #24
0
        public string saveRow(itemUnitUser newObject, int userId)
        {
            string message = "";

            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;
            }
            if (newObject.itemUnitId == 0 || newObject.itemUnitId == null)
            {
                Nullable <int> id = null;
                newObject.itemUnitId = 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 <itemUnitUser>();
                    if (newObject.id == 0)
                    {
                        newObject.createDate   = DateTime.Now;
                        newObject.updateDate   = DateTime.Now;
                        newObject.updateUserId = userId;
                        newObject.userId       = userId;

                        locationEntity.Add(newObject);
                        entity.SaveChanges();
                        message = newObject.id.ToString();
                    }
                    else
                    {
                        var tmpObject = entity.itemUnitUser.Where(p => p.id == newObject.id).FirstOrDefault();

                        tmpObject.updateDate = DateTime.Now;


                        tmpObject.id         = newObject.id;
                        tmpObject.itemUnitId = newObject.itemUnitId;
                        tmpObject.userId     = userId;
                        tmpObject.notes      = newObject.notes;
                        tmpObject.createDate = newObject.createDate;

                        // tmpObject.createUserId = newObject.createUserId;
                        tmpObject.updateUserId = newObject.updateUserId;
                        tmpObject.isActive     = newObject.isActive;


                        entity.SaveChanges();

                        message = tmpObject.id.ToString();
                    }
                    //  entity.SaveChanges();
                }
            }
            catch
            {
                message = "-1";
            }
            return(message);
        }
コード例 #25
0
        //////////////////////
        ///

        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");
            }
        }
コード例 #26
0
        public string Save(string medalObject)
        {
            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)
            {
                medalObject = medalObject.Replace("\\", string.Empty);
                medalObject = medalObject.Trim('"');
                medals Object = JsonConvert.DeserializeObject<medals>(medalObject, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None });
                try
                {
                    using (incposdbEntities entity = new incposdbEntities())
                    {
                        var medalEntity = entity.Set<medals>();
                        if (Object.medalId == 0)
                        {

                            Object.createDate = DateTime.Now;
                            Object.updateDate = DateTime.Now;
                            Object.updateUserId = Object.createUserId;
                            medalEntity.Add(Object);
                            entity.SaveChanges();
                      message = Object.medalId.ToString();
                        }
                        else
                        {

                            var tmpmedal = entity.medals.Where(p => p.medalId == Object.medalId).FirstOrDefault();

                            tmpmedal.medalId = Object.medalId;

                            tmpmedal.name = Object.name;

                            tmpmedal.notes = Object.notes;

                            tmpmedal.createDate = Object.createDate;
                            tmpmedal.updateDate = Object.updateDate;
                            tmpmedal.createUserId = Object.createUserId;
                            tmpmedal.updateUserId = Object.updateUserId;
                            tmpmedal.isActive = Object.isActive;
                            tmpmedal.updateDate = DateTime.Now;// server current date;
                            tmpmedal.updateUserId = Object.updateUserId;
                            tmpmedal.symbol = Object.symbol;
                   tmpmedal.CashPointsRequired=Object.CashPointsRequired;
                   tmpmedal.invoiceCountPointsRequired=Object.invoiceCountPointsRequired;

                            entity.SaveChanges();

                            message = tmpmedal.medalId.ToString();
                        }

                    }
                    return message;
                }

                catch
                {
                    return "-1";
                }
            }
            else
                return "-1";
        }
コード例 #27
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 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());
                }
            }
        }
コード例 #28
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              shippingCompaniesObject = "";
                shippingCompanies   newObject = null;
                IEnumerable <Claim> claims    = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "itemObject")
                    {
                        shippingCompaniesObject = c.Value.Replace("\\", string.Empty);
                        shippingCompaniesObject = shippingCompaniesObject.Trim('"');
                        newObject = JsonConvert.DeserializeObject <shippingCompanies>(shippingCompaniesObject, 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())
                    {
                        var locationEntity = entity.Set <shippingCompanies>();
                        if (newObject.shippingCompanyId == 0)
                        {
                            newObject.createDate   = DateTime.Now;
                            newObject.updateDate   = DateTime.Now;
                            newObject.updateUserId = newObject.createUserId;


                            locationEntity.Add(newObject);
                            entity.SaveChanges();
                            message = newObject.shippingCompanyId.ToString();
                        }
                        else
                        {
                            var tmpObject = entity.shippingCompanies.Where(p => p.shippingCompanyId == newObject.shippingCompanyId).FirstOrDefault();

                            tmpObject.updateDate   = DateTime.Now;
                            tmpObject.updateUserId = newObject.updateUserId;

                            tmpObject.name             = newObject.name;
                            tmpObject.RealDeliveryCost = newObject.RealDeliveryCost;
                            tmpObject.deliveryCost     = newObject.deliveryCost;
                            tmpObject.deliveryType     = newObject.deliveryType;
                            tmpObject.notes            = newObject.notes;
                            tmpObject.isActive         = newObject.isActive;
                            tmpObject.balance          = newObject.balance;
                            tmpObject.balanceType      = newObject.balanceType;
                            tmpObject.email            = newObject.email;
                            tmpObject.phone            = newObject.phone;
                            tmpObject.mobile           = newObject.mobile;
                            tmpObject.fax     = newObject.fax;
                            tmpObject.address = newObject.address;

                            entity.SaveChanges();

                            message = tmpObject.shippingCompanyId.ToString();
                        }
                        //  entity.SaveChanges();
                    }
                }
                catch
                {
                    message = "-1";
                }
            }
            return(TokenManager.GenerateToken(message));
        }
コード例 #29
0
        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;
        }
コード例 #30
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));
                }
            }
        }