Example #1
0
        public async Task <JsonResult> GetHeisListing(HeisIdentification model)
        {
            IHeisService heisCourseService = new HeisService();
            var          wmsdsResponse     = await heisCourseService.GetHeisIdentifications(1, model.DistrictId, model.TehsilId, model.FarmerName, model.FarmerCNIC);

            return(Json(wmsdsResponse.Collections, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public async Task <WmsdsResponse <int> > AddHeisIdentification(HeisIdentification heisIdentification)
        {
            var wmsdResponse = new WmsdsResponse <int>();

            if (heisIdentification == null)
            {
                wmsdResponse.ResponseCode    = EnumStatus.EmptyObject;
                wmsdResponse.ResponseMessage = "Object is empty.";
                return(wmsdResponse);
            }

            if (heisIdentification.DistrictId <= 0 || string.IsNullOrEmpty(heisIdentification.DistrictName))
            {
                wmsdResponse.ResponseCode    = EnumStatus.ValidationFailed;;
                wmsdResponse.ResponseMessage = "DistrictId is a required field.";
                return(wmsdResponse);
            }

            if (heisIdentification.TehsilId <= 0 || string.IsNullOrEmpty(heisIdentification.TehsilName))
            {
                wmsdResponse.ResponseCode    = EnumStatus.ValidationFailed;;
                wmsdResponse.ResponseMessage = "TehsilId is a required field.";
                return(wmsdResponse);
            }
            if (await IsHeisIdentificationAlreadyExist(heisIdentification))
            {
                wmsdResponse.ResponseCode    = EnumStatus.AlreadyExist;
                wmsdResponse.ResponseMessage = "Watercourse already exists.";
                return(wmsdResponse);
            }
            //Check if status is Addation than there must be a regular water course
            try
            {
                using (var _dbContext = new EntityContext())
                {
                    _dbContext.HeisIdentifications.Add(heisIdentification);
                    var response = await _dbContext.SaveChangesAsync();

                    if (response > 0)
                    {
                        wmsdResponse.ResponseCode    = EnumStatus.Success;;
                        wmsdResponse.ResponseMessage = "Identicification has been added successfully.";
                        return(wmsdResponse);
                    }
                    else
                    {
                        wmsdResponse.ResponseCode    = EnumStatus.Failed;;
                        wmsdResponse.ResponseMessage = "Failed to add channel.";
                        return(wmsdResponse);
                    }
                }
            }
            catch (Exception ex)
            {
                wmsdResponse.ResponseCode    = EnumStatus.InternalServer;
                wmsdResponse.ResponseMessage = ex.Message;
                return(wmsdResponse);
            }
        }
Example #3
0
        private async Task <bool> IsHeisIdentificationAlreadyExist(HeisIdentification heisIdentification)
        {
            using (var _dbContext = new EntityContext())
            {
                var wcIdentificationDb = await _dbContext.HeisIdentifications
                                         .Where(c => c.FarmerCNIC == heisIdentification.FarmerCNIC)
                                         .FirstOrDefaultAsync();

                return(wcIdentificationDb == null ? false : true);
            }
        }
Example #4
0
        public async Task <ActionResult> AddHeisIdentification(HeisIdentification model)
        {
            try
            {
                //model.CreatedAt = DateTime.Now;
                IHeisService heisCourseService = new HeisService();
                var          response          = await heisCourseService.AddHeisIdentification(model);

                if (response.ResponseCode == Entities.EnumStatus.Success)
                {
                }

                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new { FormId = 0, HttpStatusCode = HttpStatusCode.NotImplemented }));
            }
        }