Esempio n. 1
0
        public async Task <JsonResult> GetWcListing(WcIdentification model)
        {
            IWaterCourseService waterCourseService             = new WaterCourseService();
            WmsdsResponse <WcIdentification> WcIdentifications = await waterCourseService.GetWcIdentifications(1, model.DistrictId, model.TehsilId, model.ChannelId, 0, null);

            return(Json(WcIdentifications.Collections, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        /// <summary>
        /// Is watercourse exists with Regular status
        /// </summary>
        /// <param name="wcIdentification"></param>
        /// <returns></returns>
        private async Task <bool> IsWcIdentificationAlreadyExist(WcIdentification wcIdentification)
        {
            using (var _dbContext = new EntityContext())
            {
                var wcIdentificationDb = await _dbContext.WcIdentifications
                                         .Where(c => c.DistrictId == wcIdentification.DistrictId)
                                         .Where(c => c.TehsilId == wcIdentification.TehsilId)
                                         .Where(c => c.ChannelId == wcIdentification.ChannelId)
                                         .Where(c => c.WaterCourseId == wcIdentification.WaterCourseId)
                                         .FirstOrDefaultAsync();

                return(wcIdentificationDb == null ? false : true);
            }
        }
Esempio n. 3
0
        public async Task <ActionResult> AddWatercourseIdentification(WcIdentification model)
        {
            try
            {
                model.CreatedAt = DateTime.Now;
                IWaterCourseService waterCourseService = new WaterCourseService();
                var response = await waterCourseService.AddIdentification(model);

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

                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new { FormId = 0, HttpStatusCode = HttpStatusCode.NotImplemented }));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Add Identification of a water course
        /// </summary>
        /// <param name="wcIdentification"></param>
        /// <returns></returns>
        public async Task <WmsdsResponse <int> > AddIdentification(WcIdentification wcIdentification)
        {
            var wmsdResponse = new WmsdsResponse <int>();

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

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

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

            if (wcIdentification.ChannelId <= 0 || string.IsNullOrEmpty(wcIdentification.ChannelName))
            {
                wmsdResponse.ResponseCode    = EnumStatus.ValidationFailed;;
                wmsdResponse.ResponseMessage = "Channel Name is a required field.";
                return(wmsdResponse);
            }
            if (wcIdentification.WaterCourseId <= 0 || string.IsNullOrEmpty(wcIdentification.WaterCourseNo))
            {
                wmsdResponse.ResponseCode    = EnumStatus.ValidationFailed;;
                wmsdResponse.ResponseMessage = "WaterCourse No is a required field.";
                return(wmsdResponse);
            }

            //Check If WcIdentification Already Exists with Regular Status
            //if (wcIdentification.ImprovementType == EnumWcImprovementType.Regular.ToString() && await IsWcIdentificationAlreadyExist(wcIdentification))
            //{
            //    wmsdResponse.ResponseCode = EnumStatus.AlreadyExist;
            //    wmsdResponse.ResponseMessage = "Watercourse already exists.";
            //    return wmsdResponse;
            //}

            //if (wcIdentification.ImprovementType.Equals(EnumWcImprovementType.Additional.ToString(), StringComparison.OrdinalIgnoreCase))
            //{
            //    if (!await IsWcIdentificationAlreadyExist(wcIdentification))
            //    {
            //        wmsdResponse.ResponseCode = EnumStatus.NotFound;
            //        wmsdResponse.ResponseMessage = "No Watercourse found with Regular Status.";
            //        return wmsdResponse;
            //    }
            //}

            if (await IsWcIdentificationAlreadyExist(wcIdentification))
            {
                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.WcIdentifications.Add(wcIdentification);
                    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);
            }
        }