Beispiel #1
0
        public async Task <HttpResponseMessage> Post([FromBody] List <EmployeeModel> mEmployeeModel)
        {
            var    formatter = RequestFormat.JsonFormaterString();
            string msg       = "";

            try
            {
                if (string.IsNullOrEmpty(mEmployeeModel.ElementAt(0).EmCode))
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        Output = "error", Msg = "Employee Code is Empty"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(mEmployeeModel.ElementAt(0).EmName))
                {
                    return(Request.CreateResponse(HttpStatusCode.OK,
                                                  new Confirmation {
                        Output = "error", Msg = "Employee Name is Empty"
                    }, formatter));
                }
                else
                {
                    if (_gtEmployeeGetway.FncSeekRecordNew("tbl_HR_GLO_EMPLOYEE", "Id=" + mEmployeeModel.ElementAt(0).EmId + ""))
                    {
                        msg = await _gtEmployeeGetway.Update(mEmployeeModel);

                        return(Request.CreateResponse(HttpStatusCode.OK,
                                                      new Confirmation {
                            Output = "success", Msg = msg
                        }, formatter));
                    }
                    else
                    {
                        if (_gtEmployeeGetway.FncSeekRecordNew("tbl_HR_GLO_EMPLOYEE", "Code='" + mEmployeeModel.ElementAt(0).EmCode + "'"))
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                                Output = "error", Msg = "Employee code already exists"
                            }, formatter));
                        }


                        msg = await _gtEmployeeGetway.Save(mEmployeeModel);

                        return(Request.CreateResponse(HttpStatusCode.OK,
                                                      new Confirmation {
                            Output = "success", Msg = msg
                        }, formatter));
                    }
                }
                //if (mEmployeeModel.ElementAt(0).PtIndoorId == 0)
                //{
                //    return Request.CreateResponse(HttpStatusCode.OK, new Confirmation { Output = "error", Msg = "Name is Null" });
                //}
                //else
                //{
                //    string msg = await _gtEmployeeGetway.Save(mEmployeeModel);
                //    return Request.CreateResponse(HttpStatusCode.OK, new Confirmation { Output = "success", Msg = msg }, formate);
                //}
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                    Output = "error", Msg = ex.ToString()
                }, formatter));
            }
        }