public async Task <ActionResult <TSTodo> > Get([FromBody] TSTodo TSTodo)
        {
            string UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(UserID, "Requested todo", MethodBase.GetCurrentMethod());

            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV
            {
                Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5),
                IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10)
            };


            if (!string.IsNullOrEmpty(ClientSymmKeyAndIV.Key))
            {
                TSTodo result = await TS.GetTodo(TSTodo);

                GlobalFunctions.CmdEncryptEntitySymm(result, ClientSymmKeyAndIV);


                return(result);
            }
            else
            {
                return(new TSTodo());
            }
        }
        public async Task <ActionResult> Delete([FromBody] TSTodo TSTodo)
        {
            string userID   = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            string userName = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10);

            await TS.AddActivityLog(userID, "delete todo", MethodBase.GetCurrentMethod());

            GlobalFunctions.CmdDecryptEntityAsymm(TSTodo);

            bool b = await TS.DeleteTodo(TSTodo);

            if (b)
            {
                TSUser currUser = new TSUser()
                {
                    UserID   = userID,
                    UserName = userName,
                };

                await TS.UpdateUserTodosCount(currUser, 1);

                await TS.UpdateSettingCounter("AllUsers", "TodosCount", false);

                return(Ok("OK"));
            }
            else
            {
                return(Ok("Error:Can't add new todo!"));
            }
        }
示例#3
0
        public async Task <ActionResult> Update(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "todo/update")] HttpRequest req,
            ILogger log)
        {
            TSTodo tsTodo = await MyFromBody <TSTodo> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));


            Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));

            await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "put todo", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));



            bool b = await CosmosAPI.cosmosDBClientTodo.UpdateTodo(tsTodo, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            if (b)
            {
                return(new OkObjectResult("OK"));
            }
            else
            {
                return(new OkObjectResult("Error:Can't add new todo!"));
            }
        }
示例#4
0
 public TSTodoEntity(TSTodo tsTodo)
 {
     PartitionKey      = tsTodo.UserID;
     RowKey            = tsTodo.TodoID.ToString();
     Name              = tsTodo.Name;
     Description       = tsTodo.Description;
     HasDueDate        = tsTodo.HasDueDate;
     DueDate           = tsTodo.DueDate;
     CreateDate        = tsTodo.CreateDate;
     Priority          = tsTodo.Priority;
     IsDone            = tsTodo.IsDone;
     CategoryID        = tsTodo.CategoryID;
     HasRemindDate     = tsTodo.HasRemindDate;
     RemindDate        = tsTodo.RemindDate;
     IsReminderEmailed = tsTodo.IsReminderEmailed;
 }
示例#5
0
        public async Task <ActionResult <TSTodo> > Get(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "todo/get")] HttpRequest req,
            ILogger log)
        {
            TSTodo tsTodo = await MyFromBody <TSTodo> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));


            Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));

            await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "Requested todo", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));



            return(await CosmosAPI.cosmosDBClientTodo.GetTodo(tsTodo, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));
        }
        public async Task <ActionResult> Put([FromBody] TSTodo TSTodo)
        {
            string UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(UserID, "put todo", MethodBase.GetCurrentMethod());

            GlobalFunctions.CmdDecryptEntityAsymm(TSTodo);

            bool b = await TS.UpdateTodo(TSTodo);

            if (b)
            {
                return(Ok("OK"));
            }
            else
            {
                return(Ok("Error:Can't add new todo!"));
            }
        }
        public CosmosDocTodo(TSTodo tsTodo)
        {
            UserID            = tsTodo.UserID;
            ID                = tsTodo.ID;
            Name              = tsTodo.Name;
            Description       = tsTodo.Description;
            HasDueDate        = tsTodo.HasDueDate;
            DueDate           = tsTodo.DueDate;
            CreateDate        = tsTodo.CreateDate;
            Priority          = tsTodo.Priority;
            IsDone            = tsTodo.IsDone;
            CategoryID        = tsTodo.CategoryID;
            HasRemindDate     = tsTodo.HasRemindDate;
            RemindDate        = tsTodo.RemindDate;
            IsReminderEmailed = tsTodo.IsReminderEmailed;


            DocType = (int)DocTypeEnum.Todo;
            GeneratePK();
        }
示例#8
0
        public static async Task <string> CmdUpdateTodo(TSTodo ParTSTodo)
        {
            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalData.CurrJWT);

            GlobalFunctions.CmdTrimEntity(ParTSTodo);

            TSTodo tsTodoForSend = GlobalFunctions.CopyObject <TSTodo>(ParTSTodo);

            GlobalFunctions.CmdAdjustDate(tsTodoForSend, true);


            string result = await httpClient.PutJsonAsync <string>("todo/update", tsTodoForSend);


            httpClient.DefaultRequestHeaders.Accept.Clear();


            return(result);
        }
示例#9
0
        public async Task <ActionResult> Add(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "todo/add")] HttpRequest req,
            ILogger log)
        {
            TSTodo tsTodo = await MyFromBody <TSTodo> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            Guid   userID   = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));
            string userName = LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            await CosmosAPI.cosmosDBClientActivity.AddActivityLog(userID, "post todo", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));


            tsTodo.ID         = Guid.NewGuid();
            tsTodo.CreateDate = DateTime.Now;


            bool b = await CosmosAPI.cosmosDBClientTodo.AddTodo(tsTodo, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            if (b)
            {
                TSUser currUser = new TSUser()
                {
                    ID       = userID,
                    UserName = userName,
                };

                await CosmosAPI.cosmosDBClientUser.UpdateUserTodosCount(currUser, 1, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

                await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "TodosCount", true, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

                return(new OkObjectResult("OK"));
            }
            else
            {
                return(new OkObjectResult("Error:Can't add new todo!"));
            }
        }
        public async Task <ActionResult> Post([FromBody] TSTodo TSTodo)
        {
            string userID   = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            string userName = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10);
            await TS.AddActivityLog(userID, "post todo", MethodBase.GetCurrentMethod());

            GlobalFunctions.CmdDecryptEntityAsymm(TSTodo);
            string a = await TS.GetNewID(TSTodo.UserID, "LastTodoID", false);

            TSTodo.TodoID     = int.Parse(a);
            TSTodo.CreateDate = DateTime.Now;


            bool b = await TS.AddTodo(TSTodo);

            if (b)
            {
                await GlobalFunctions.NotifyAdmin("New todo " + userName);


                TSUser currUser = new TSUser()
                {
                    UserID   = userID,
                    UserName = userName,
                };

                await TS.UpdateUserTodosCount(currUser, 1);

                await TS.UpdateSettingCounter("AllUsers", "TodosCount", true);

                return(Ok("OK"));
            }
            else
            {
                return(Ok("Error:Can't add new todo!"));
            }
        }
示例#11
0
        public static async Task <string> CmdDeleteTodo(TSTodo ParTSTodo)
        {
            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalData.CurrJWT);

            GlobalFunctions.CmdTrimEntity(ParTSTodo);

            //TSTodo tsTodoForSend = GlobalFunctions.CopyObject<TSTodo>(ParTSTodo);

            TSTodo tsTodoForSend = new TSTodo();

            tsTodoForSend.UserID = ParTSTodo.UserID;
            tsTodoForSend.ID     = ParTSTodo.ID;


            string result = await httpClient.SendJsonAsync <string>(HttpMethod.Delete, "todo/delete", tsTodoForSend);


            httpClient.DefaultRequestHeaders.Accept.Clear();


            return(result);
        }
 public async Task <TSTodo> GetTodo(TSTodo tsTodo, List <string> CallTrace)
 {
     return((await cosmosDBClientBase.GetItemAsync(new CosmosDocTodo(tsTodo), pkPrefix, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()))).toTSTodo());
 }
 public async Task <bool> UpdateTodo(TSTodo tsTodo, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.UpdateItemAsync(new CosmosDocTodo(tsTodo), LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }