public string Delete(string token)
        {
            token = TokenManager.readToken(HttpContext.Current.Request);
            string message = "";
            var    strP    = TokenManager.GetPrincipal(token);

            if (strP != "0") //invalid authorization
            {
                return(TokenManager.GenerateToken(strP));
            }
            else
            {
                int                 propertyItemId = 0;
                int                 userId         = 0;
                Boolean             final          = false;
                IEnumerable <Claim> claims         = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "itemId")
                    {
                        propertyItemId = int.Parse(c.Value);
                    }
                    else if (c.Type == "userId")
                    {
                        userId = int.Parse(c.Value);
                    }
                    else if (c.Type == "final")
                    {
                        final = bool.Parse(c.Value);
                    }
                }
                if (final)
                {
                    try
                    {
                        using (incposdbEntities entity = new incposdbEntities())
                        {
                            propertiesItems PropertDelete = entity.propertiesItems.Find(propertyItemId);
                            entity.propertiesItems.Remove(PropertDelete);
                            message = entity.SaveChanges().ToString();
                            return(TokenManager.GenerateToken(message));
                        }
                    }
                    catch
                    {
                        message = "0";
                        return(TokenManager.GenerateToken(message));
                    }
                }
                else
                {
                    try
                    {
                        using (incposdbEntities entity = new incposdbEntities())
                        {
                            propertiesItems PropertDelete = entity.propertiesItems.Find(propertyItemId);
                            PropertDelete.isActive     = 0;
                            PropertDelete.updateUserId = userId;
                            PropertDelete.updateDate   = DateTime.Now;
                            message = entity.SaveChanges().ToString();
                            return(TokenManager.GenerateToken(message));
                        }
                    }
                    catch
                    {
                        message = "0";
                        return(TokenManager.GenerateToken(message));
                    }
                }
            }
        }
        public string 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));
                }
            }
        }