示例#1
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"));
                }
            }
        }
示例#2
0
        public string setConfiguration(string token)
        {
            token = TokenManager.readToken(HttpContext.Current.Request);

            var strP = TokenManager.GetPrincipal(token);

            if (strP != "0") //invalid authorization
            {
                return(TokenManager.GenerateToken(strP));
            }
            else
            {
                string setObject                = "";
                string activationCode           = "";
                string deviceCode               = "";
                int    countryId                = 0;
                string userName                 = "";
                string password                 = "";
                string branchName               = "";
                string branchCode               = "";
                string branchMobile             = "";
                string posName                  = "";
                List <setValuesModel> newObject = null;

                IEnumerable <Claim> claims = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "setValues")
                    {
                        setObject = c.Value.Replace("\\", string.Empty);
                        setObject = setObject.Trim('"');
                        newObject = JsonConvert.DeserializeObject <List <setValuesModel> >(setObject, new IsoDateTimeConverter {
                            DateTimeFormat = "dd/MM/yyyy"
                        });
                    }
                    else if (c.Type == "activationCode")
                    {
                        activationCode = c.Value;
                    }
                    else if (c.Type == "deviceCode")
                    {
                        deviceCode = c.Value;
                    }
                    else if (c.Type == "countryId")
                    {
                        countryId = int.Parse(c.Value);
                    }
                    else if (c.Type == "userName")
                    {
                        userName = c.Value;
                    }
                    else if (c.Type == "password")
                    {
                        password = c.Value;
                    }
                    else if (c.Type == "branchMobile")
                    {
                        branchMobile = c.Value;
                    }
                    else if (c.Type == "branchName")
                    {
                        branchName = c.Value;
                    }
                    else if (c.Type == "branchCode")
                    {
                        branchCode = c.Value;
                    }
                    else if (c.Type == "posName")
                    {
                        posName = c.Value;
                    }
                }

                try
                {
                    using (incposdbEntities entity = new incposdbEntities())
                    {
                        pos tmpPos     = new pos();
                        var unitEntity = entity.Set <pos>();

                        var validSerial = entity.posSerials.Where(x => x.posSerial == activationCode).FirstOrDefault();
                        if (validSerial != null) // activation code is correct
                        {
                            var serialExist = entity.posSetting.Where(x => x.posSerialId == validSerial.id).FirstOrDefault();

                            if (serialExist == null) // activation code is available
                            {
                                var pos = entity.pos.Find(1);
                                pos.name = posName;
                                entity.SaveChanges();
                                #region add pos settings record
                                var posSett = new posSetting()
                                {
                                    posId         = pos.posId,
                                    posSerialId   = validSerial.id,
                                    posDeviceCode = deviceCode,
                                    createDate    = DateTime.Now,
                                    updateDate    = DateTime.Now,
                                };
                                entity.posSetting.Add(posSett);
                                #endregion
                                #region region settings
                                List <countriesCodes> objectlist = entity.countriesCodes.Where(x => x.isDefault == 1).ToList();
                                if (objectlist.Count > 0)
                                {
                                    for (int i = 0; i < objectlist.Count; i++)
                                    {
                                        objectlist[i].isDefault = 0;
                                    }
                                }
                                // set is selected to isdefault=1
                                countriesCodes objectrow = entity.countriesCodes.Find(countryId);
                                if (objectrow != null)
                                {
                                    objectrow.isDefault = 1;
                                }

                                #endregion
                                #region update user
                                var user = entity.users.Find(2);
                                user.username = userName;
                                user.password = password;
                                #endregion
                                #region update branch
                                var branch = entity.branches.Find(2);
                                branch.name   = branchName;
                                branch.code   = branchCode;
                                branch.mobile = branchMobile;
                                #endregion
                                #region company info
                                foreach (setValuesModel v in newObject)
                                {
                                    var setId    = entity.setting.Where(x => x.name == v.name).Select(x => x.settingId).Single();
                                    var setValue = entity.setValues.Where(x => x.settingId == setId).FirstOrDefault();
                                    setValue.value = v.value;
                                }
                                #endregion
                                entity.SaveChanges();
                                return(TokenManager.GenerateToken(pos.posId.ToString()));
                            }
                            else
                            {
                                return(TokenManager.GenerateToken("-3")); // activation code is unavailable
                            }
                        }
                        else
                        {
                            return(TokenManager.GenerateToken("-2")); // serial is wrong
                        }
                    }
                }
                catch
                {
                    return(TokenManager.GenerateToken("0"));
                }
            }
        }
        public string    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    = "";
                posSetting          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 <posSetting>(Object, new IsoDateTimeConverter {
                            DateTimeFormat = "dd/MM/yyyy"
                        });
                        break;
                    }
                }
                if (newObject != null)
                {
                    posSetting tmpObject;
                    if (newObject.posId == 0 || newObject.posId == null)
                    {
                        Nullable <int> id = null;
                        newObject.posId = id;
                    }
                    if (newObject.reportPrinterId == 0 || newObject.reportPrinterId == null)
                    {
                        Nullable <int> id = null;
                        newObject.reportPrinterId = id;
                    }
                    if (newObject.saleInvPapersizeId == 0 || newObject.saleInvPapersizeId == null)
                    {
                        Nullable <int> id = null;
                        newObject.saleInvPapersizeId = id;
                    }
                    if (newObject.saleInvPrinterId == 0 || newObject.saleInvPrinterId == null)
                    {
                        Nullable <int> id = null;
                        newObject.saleInvPrinterId = id;
                    }

                    try
                    {
                        using (incposdbEntities entity = new incposdbEntities())
                        {
                            var locationEntity = entity.Set <posSetting>();
                            if (newObject.posSettingId == 0)
                            {
                                locationEntity.Add(newObject);
                                entity.SaveChanges();
                                message = newObject.posSettingId.ToString();
                            }
                            else
                            {
                                tmpObject = entity.posSetting.Where(p => p.posSettingId == newObject.posSettingId).FirstOrDefault();


                                tmpObject.posSettingId = newObject.posSettingId;

                                tmpObject.posId              = newObject.posId;
                                tmpObject.saleInvPrinterId   = newObject.saleInvPrinterId;
                                tmpObject.reportPrinterId    = newObject.reportPrinterId;
                                tmpObject.saleInvPapersizeId = newObject.saleInvPapersizeId;
                                tmpObject.docPapersizeId     = newObject.docPapersizeId;
                                //  tmpObject.posSerial = newObject.posSerial;      public Nullable<int> docPapersizeId { get; set; }



                                entity.SaveChanges();

                                message = tmpObject.posSettingId.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('"');
            //    posSetting newObject = JsonConvert.DeserializeObject<posSetting>(Object, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None });
            //    if (newObject.posId == 0 || newObject.posId == null)
            //    {
            //        Nullable<int> id = null;
            //        newObject.posId = id;
            //    }
            //    if (newObject.reportPrinterId == 0 || newObject.reportPrinterId == null)
            //    {
            //        Nullable<int> id = null;
            //        newObject.reportPrinterId = id;
            //    }
            //    if (newObject.saleInvPapersizeId == 0 || newObject.saleInvPapersizeId == null)
            //    {
            //        Nullable<int> id = null;
            //        newObject.saleInvPapersizeId = id;
            //    }
            //    if (newObject.saleInvPrinterId == 0 || newObject.saleInvPrinterId == null)
            //    {
            //        Nullable<int> id = null;
            //        newObject.saleInvPrinterId = id;
            //    }

            //    try
            //    {
            //        using (incposdbEntities entity = new incposdbEntities())
            //        {
            //            var locationEntity = entity.Set<posSetting>();
            //            if (newObject.posSettingId == 0)
            //            {



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


            //                tmpObject.posSettingId = newObject.posSettingId;

            //                tmpObject.posId = newObject.posId;
            //                tmpObject.saleInvPrinterId = newObject.saleInvPrinterId;
            //                tmpObject.reportPrinterId = newObject.reportPrinterId;
            //                tmpObject.saleInvPapersizeId = newObject.saleInvPapersizeId;
            //                tmpObject.docPapersizeId = newObject.docPapersizeId;
            //                //  tmpObject.posSerial = newObject.posSerial;      public Nullable<int> docPapersizeId { get; set; }



            //                entity.SaveChanges();

            //                message = tmpObject.posSettingId.ToString();
            //            }
            //            //  entity.SaveChanges();
            //        }
            //    }
            //    catch
            //    {
            //        message = "-1";
            //    }
            //}
            //return message;
        }
        public string   Delete(string token)
        {
            //int posSettingId  Save()
            string message = "";



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

            if (strP != "0") //invalid authorization
            {
                return(TokenManager.GenerateToken(strP));
            }
            else
            {
                int posSettingId = 0;


                IEnumerable <Claim> claims = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "posSettingId")
                    {
                        posSettingId = int.Parse(c.Value);
                    }
                }

                try
                {
                    using (incposdbEntities entity = new incposdbEntities())
                    {
                        posSetting objectDelete = entity.posSetting.Find(posSettingId);

                        entity.posSetting.Remove(objectDelete);
                        message = entity.SaveChanges().ToString();
                    }
                    return(TokenManager.GenerateToken(message));
                }
                catch
                {
                    return(TokenManager.GenerateToken("0"));
                }
            }

            //var re = Request;
            //
            //string token = "";
            //int message = 0;
            //if (headers.Contains("APIKey"))
            //{
            //    token = headers.GetValues("APIKey").First();
            //}

            //Validation validation = new Validation();
            //bool valid = validation.CheckApiKey(token);
            //if (valid)
            //{

            //    try
            //    {
            //        using (incposdbEntities entity = new incposdbEntities())
            //        {
            //            posSetting objectDelete = entity.posSetting.Find(posSettingId);

            //            entity.posSetting.Remove(objectDelete);
            //            message = entity.SaveChanges();

            //            return message.ToString();
            //        }
            //    }
            //    catch
            //    {
            //        return "-1";
            //    }


            //}
            //else
            //    return "-3";
        }
        private int Save(posSetting newObject)
        {
            int message = 0;

            if (newObject != null)
            {
                posSetting tmpObject;
                if (newObject.posId == 0 || newObject.posId == null)
                {
                    Nullable <int> id = null;
                    newObject.posId = id;
                }
                if (newObject.reportPrinterId == 0 || newObject.reportPrinterId == null)
                {
                    Nullable <int> id = null;
                    newObject.reportPrinterId = id;
                }
                if (newObject.saleInvPapersizeId == 0 || newObject.saleInvPapersizeId == null)
                {
                    Nullable <int> id = null;
                    newObject.saleInvPapersizeId = id;
                }
                if (newObject.saleInvPrinterId == 0 || newObject.saleInvPrinterId == null)
                {
                    Nullable <int> id = null;
                    newObject.saleInvPrinterId = id;
                }

                try
                {
                    using (incposdbEntities entity = new incposdbEntities())
                    {
                        var locationEntity = entity.Set <posSetting>();
                        if (newObject.posSettingId == 0)
                        {
                            locationEntity.Add(newObject);
                            entity.SaveChanges();
                            message = newObject.posSettingId;
                        }
                        else
                        {
                            tmpObject = entity.posSetting.Where(p => p.posSettingId == newObject.posSettingId).FirstOrDefault();


                            tmpObject.posSettingId = newObject.posSettingId;

                            tmpObject.posId              = newObject.posId;
                            tmpObject.saleInvPrinterId   = newObject.saleInvPrinterId;
                            tmpObject.reportPrinterId    = newObject.reportPrinterId;
                            tmpObject.saleInvPapersizeId = newObject.saleInvPapersizeId;
                            tmpObject.docPapersizeId     = newObject.docPapersizeId;
                            //  tmpObject.posSerial = newObject.posSerial;      public Nullable<int> docPapersizeId { get; set; }



                            entity.SaveChanges();

                            message = tmpObject.posSettingId;
                        }
                        //  entity.SaveChanges();
                    }
                    return(message);
                }
                catch
                {
                    message = 0;
                    return(message);
                }
            }
            else
            {
                return(-1);
            }
        }