示例#1
0
        public PlotDetailResponse CreateUpdatePlot([FromBody] PlotDetailResponse det)
        {
            string str = Newtonsoft.Json.JsonConvert.SerializeObject(det);

            bool res = default(bool);

            if (det.PlotName == string.Empty && det.PlotSize <= default(int) && det.FarmId == string.Empty)
            {
                det.Error  = "Failed to create or update farm request structure invalid";
                det.Status = ResponseStatus.Failed;
                return(det);
            }

            try
            {
                if (HttpContext.Current.Session[ApplicationConstant.UserSession] != null)
                {
                    SessionData sessionObject = (SessionData)HttpContext.Current.Session[ApplicationConstant.UserSession];

                    PlotDetail resdata = new PlotDetail();
                    resdata.PlotName = det.PlotName;
                    resdata.PlotSize = det.PlotSize;
                    resdata.Organic  = det.Organic;
                    resdata.SoilId   = string.IsNullOrEmpty(det.SoilId) == true?default(int):Convert.ToInt32(EncryptionHelper.AesDecryption(det.SoilId, EncryptionKey.LOG));
                    resdata.SoilPhId = string.IsNullOrEmpty(det.SoilPhId) == true ? default(int) : Convert.ToInt32(EncryptionHelper.AesDecryption(det.SoilPhId, EncryptionKey.LOG));
                    resdata.Notes    = det.Notes;
                    resdata.FarmId   = Convert.ToInt32(EncryptionHelper.AesDecryption(det.FarmId, EncryptionKey.LOG));
                    resdata.PlotId   = !string.IsNullOrEmpty(det.PlotId) ? Convert.ToInt32(EncryptionHelper.AesDecryption(det.PlotId, EncryptionKey.LOG)) : 0;
                    resdata.UserID   = sessionObject._userId;

                    AggieGlobalLogManager.Info("PlotController :: CreateUpdatePlot started ");
                    var connectionString = "AggieGlobal";
                    var repo             = new PlotManager(connectionString);
                    res        = repo.CreateUpdatePlot(resdata);
                    det.Status = ResponseStatus.Successful;
                    det.PlotId = EncryptionHelper.AesEncryption(resdata.PlotId.ToString(), EncryptionKey.LOG);
                    repo.Dispose();
                }
            }
            catch (Exception ex)
            {
                det.Error  = "Failed to create or update farm";
                det.Status = ResponseStatus.Failed;
                AggieGlobalLogManager.Fatal("PlotController :: CreateUpdatePlot failed :: " + ex.Message);
            }

            return(det);
        }