Exemplo n.º 1
0
        public async Task <JsonResult> Delete(string staffing_id)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(staffing_id)))
                {
                    return(Json("Error", JsonRequestBehavior.AllowGet));
                }

                PatchPostModel data = new PatchPostModel();
                data.changed.Add("is_active", false.ToString());

                var resp = await _staffingProcessor.Modify(Convert.ToInt32(staffing_id), data, CurrentUserId, CurrentDateTime);

                if (resp.success)
                {
                    return(Json(data: true, behavior: JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(data: false, behavior: JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PatchAdd([FromBody] PatchPostModel postModel)
        {
            if (postModel.IsArchived == true)
            {
                await postService.ArchivePost(postModel.Id, User.GetUserId(), true);

                return(NoContent());
            }

            return(BadRequest(ModelState));
        }
Exemplo n.º 3
0
        public async Task <ResponseModel> Modify(int id, PatchPostModel data, int adminId, DateTime currentDt)
        {
            if (data == null)
            {
                return(new ResponseDataModel <int> {
                    success = false, data = 0, message = "No data provided"
                });
            }

            if (adminId == 0)
            {
                return(new ResponseModel {
                    success = false, message = "No Administrator loogged in"
                });
            }

            return(await _repository.Modify(id, data, adminId, currentDt) ? new ResponseModel() : new ResponseModel
            {
                success = false, message = "An error saving data occurred"
            });
        }
Exemplo n.º 4
0
 public async Task <bool> Modify(int id, PatchPostModel data, int userId, DateTime currentDt)
 {
     UpdateWhereClause = $"staffing_id = {id}";
     return(await ExecUpdate(data, userId, currentDt));
 }
Exemplo n.º 5
0
        protected async Task <bool> ExecUpdate(PatchPostModel data, int userId, DateTime currentDt)
        {
            if (string.IsNullOrEmpty(UpdateWhereClause))
            {
                throw new NotImplementedException();
            }

            if (data == null || data.changed == null)
            {
                return(true);
            }

            string upd = $"UPDATE {TableName()} SET";

            int cnt = data.changed.Count;

            if (cnt == 0)
            {
                return(true);
            }

            List <object>        sqlparams = new List <object>();
            ICollection <string> keys      = data.changed.Keys;

            foreach (string key in keys)
            {
                string value = data.changed[key];
                //upd += $" {key} = @{key},";


                try
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        //sqlparams.Add(new SqlParameter($"@{key}", null));

                        upd += $" {key} = null,";
                        continue;
                    }

                    upd += $" {key} = @{key},";

                    if (string.Equals(value, "true", StringComparison.OrdinalIgnoreCase))
                    {
                        sqlparams.Add(new SqlParameter($"@{key}", true));
                        continue;
                    }

                    if (string.Equals(value, "false", StringComparison.OrdinalIgnoreCase))
                    {
                        sqlparams.Add(new SqlParameter($"@{key}", false));
                        continue;
                    }

                    sqlparams.Add(new SqlParameter($"@{key}", value));
                }
                catch (Exception ex)
                {
                    string s = ex.Message;
                    return(false);
                }
            }

            if (UpdateLastDateTime)
            {
                upd += " last_updated_by_user_id = @last_updated_by_user_id, last_updated_datetime = @last_updated_datetime";
                sqlparams.Add(new SqlParameter("@last_updated_by_user_id", userId));
                sqlparams.Add(new SqlParameter("@last_updated_datetime", currentDt));
            }
            else
            {
                upd = upd.Substring(0, upd.Length - 1);
            }

            // await ExecuteQuery($"{upd} WHERE {UpdateWhereClause}", dict);
            using (var db = new InternalSystemEntities())
            {
                try
                {
                    int recCnt = await db.Database.ExecuteSqlCommandAsync($"{upd} WHERE {UpdateWhereClause}", sqlparams.ToArray());

                    return(recCnt > 0);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Exemplo n.º 6
0
 public async Task <bool> Modify(int id, PatchPostModel data, int userId, DateTime currentDt)
 {
     return(await _data.Modify(id, data, userId, currentDt));
 }
 public async Task <HttpResponseMessage> PatchPostsAsync(string postId, PatchPostModel patchPostModel)
 {
     return(await StringExtensions.AppendPathSegments(m_baseUrl, PostsPath, postId)
            .AllowAnyHttpStatus()
            .SendJsonAsync(HttpMethod.Patch, patchPostModel));
 }