Esempio n. 1
0
        public async Task <IActionResult> Update([FromRoute] int userid, [FromRoute] int contactid, [FromBody] UserContact model)
        {
            if (model == null)
            {
                httpResult = new FSResponseMessage(FSStatusCode.BadRequest, FSStatusMessage.fail, HttpResponseMessageKey.ArgsNull);
                goto response;
            }

            try
            {
                var _data = await unitOfWorks.UserContacts().GetSingleById(userid, contactid);

                if (_data == null)
                {
                    httpResult = new FSResponseMessage(FSStatusCode.NotFound, FSStatusMessage.fail, HttpResponseMessageKey.NotFound);
                    goto response;
                }

                if (!await ValidateUpdateModel(userid, contactid, model))
                {
                    var _modelState = ModelState
                                      .Where(x => x.Value.ValidationState == ModelValidationState.Invalid)
                                      .ToDictionary(x => x.Key, x => x.Value.Errors[0].ErrorMessage);

                    httpResult = new FSResponseData <Dictionary <string, string> >(FSStatusCode.UnprocessableEntity, FSStatusMessage.fail, _modelState);
                    goto response;
                }

                unitOfWorks.UserContacts().Update(_data, model);

                int _status = await unitOfWorks.Save();

                if (_status == 1)
                {
                    httpResult = new FSResponseMessage(FSStatusCode.OK, FSStatusMessage.success, HttpResponseMessageKey.DataSuccessfullyUpdated);
                }
                else
                {
                    httpResult = new FSResponseMessage(FSStatusCode.InternalServerErrorException, FSStatusMessage.error, HttpResponseMessageKey.DataUnsuccessfullyUpdated);
                }
            }
            catch (Exception ex)
            {
                httpResult = new FSResponseMessage(FSStatusCode.InternalServerErrorException, FSStatusMessage.error, ex.Message);
            }

response:
            return(FSHttpResponse(httpResult));
        }
Esempio n. 2
0
 public async Task <IActionResult> Get([FromQuery] int page = 1, [FromQuery] int size = 10)
 {
     page = (page < 1) ? 1 : page;
     size = (size < 1) ? 10 : size;
     try
     {
         var _data = (await unitOfWorks.UserContacts().Get()).Skip((page - 1) * size).Take(size);
         httpResult = new FSResponseData <IEnumerable <UserContact> >(FSStatusCode.OK, FSStatusMessage.success, _data);
     }
     catch (Exception ex)
     {
         httpResult = new FSResponseMessage(FSStatusCode.InternalServerErrorException, FSStatusMessage.error, ex.Message);
     }
     return(FSHttpResponse(httpResult));
 }
        public async Task <IActionResult> Create([FromBody] Staff model)
        {
            if (model == null)
            {
                httpResult = new FSResponseMessage(FSStatusCode.BadRequest, FSStatusMessage.fail, HttpResponseMessageKey.ArgsNull);
                goto response;
            }

            if (!await ValidateCreateModel(model))
            {
                var _modelState = ModelState
                                  .Where(x => x.Value.ValidationState == ModelValidationState.Invalid)
                                  .ToDictionary(x => x.Key, x => x.Value.Errors[0].ErrorMessage);

                httpResult = new FSResponseData <Dictionary <string, string> >(FSStatusCode.UnprocessableEntity, FSStatusMessage.fail, _modelState);
                goto response;
            }

            try
            {
                model.Init();
                unitOfWorks.Staffs().Add(model);

                int _status = await unitOfWorks.Save();

                if (_status == 1)
                {
                    httpResult = new FSResponseMessage(FSStatusCode.OK, FSStatusMessage.success, HttpResponseMessageKey.DataSuccessfullyCreated);
                }
                else
                {
                    httpResult = new FSResponseMessage(FSStatusCode.InternalServerErrorException, FSStatusMessage.error, HttpResponseMessageKey.DataUnsuccessfullyCreated);
                }
            }
            catch (Exception ex)
            {
                httpResult = new FSResponseMessage(FSStatusCode.InternalServerErrorException, FSStatusMessage.error, ex.Message);
            }

response:
            return(FSHttpResponse(httpResult));
        }
Esempio n. 4
0
        public async Task <IActionResult> GetSingleById([FromRoute] int userid, [FromRoute] int contactid)
        {
            try
            {
                var _data = await unitOfWorks.UserContacts().GetSingleById(userid, contactid);

                if (_data == null)
                {
                    httpResult = new FSResponseMessage(FSStatusCode.NotFound, FSStatusMessage.fail, HttpResponseMessageKey.NotFound);
                }
                else
                {
                    httpResult = new FSResponseData <UserContact>(FSStatusCode.OK, FSStatusMessage.success, _data);
                }
            }
            catch (Exception ex)
            {
                httpResult = new FSResponseMessage(FSStatusCode.InternalServerErrorException, FSStatusMessage.error, ex.Message);
            }

            return(FSHttpResponse(httpResult));
        }
Esempio n. 5
0
        public async Task <IActionResult> Delete([FromRoute] int userid, [FromRoute] int contactid)
        {
            try
            {
                var _data = await unitOfWorks.UserContacts().GetSingleById(userid, contactid);

                if (_data == null)
                {
                    httpResult = new FSResponseMessage(FSStatusCode.NotFound, FSStatusMessage.fail, HttpResponseMessageKey.NotFound);
                    goto response;
                }

                if (!await IsValidToDeleteModel(_data))
                {
                    httpResult = new FSResponseMessage(FSStatusCode.BadRequest, FSStatusMessage.fail, HttpResponseMessageKey.DataHaveReferenced);
                    goto response;
                }

                unitOfWorks.UserContacts().Delete(_data);

                int _status = await unitOfWorks.Save();

                if (_status == 1)
                {
                    httpResult = new FSResponseMessage(FSStatusCode.OK, FSStatusMessage.success, HttpResponseMessageKey.DataSuccessfullyDeleted);
                }
                else
                {
                    httpResult = new FSResponseMessage(FSStatusCode.InternalServerErrorException, FSStatusMessage.error, HttpResponseMessageKey.DataUnsuccessfullyDeleted);
                }
            }
            catch (Exception ex)
            {
                httpResult = new FSResponseMessage(FSStatusCode.InternalServerErrorException, FSStatusMessage.error, ex.Message);
            }

response:
            return(FSHttpResponse(httpResult));
        }
        public async Task <IActionResult> GetSingleById([FromRoute] int memberpersonalidentitytypeid, [FromRoute] int personalidentitytypeid)
        {
            try
            {
                var _data = await unitOfWorks.MemberPersonalIdentityTypes().GetSingleById(memberpersonalidentitytypeid, personalidentitytypeid);

                if (_data == null)
                {
                    httpResult = new FSResponseMessage(FSStatusCode.NotFound, FSStatusMessage.fail, HttpResponseMessageKey.NotFound);
                }
                else
                {
                    httpResult = new FSResponseData <MemberPersonalIdentityType>(FSStatusCode.OK, FSStatusMessage.success, _data);
                }
            }
            catch (Exception ex)
            {
                httpResult = new FSResponseMessage(FSStatusCode.InternalServerErrorException, FSStatusMessage.error, ex.Message);
            }

            return(FSHttpResponse(httpResult));
        }