public ActionResult ChangeFieldStatus(int id, int status)
        {
            ResponseModel <FieldDetailViewModel> response = null;

            var service = this.Service <IFieldService>();

            try
            {
                Field field = service.ChangeFieldStatus(id, status);

                if (field != null)
                {
                    FieldDetailViewModel result = PrepareFieldDetailViewModel(field);

                    response = new ResponseModel <FieldDetailViewModel>(true, "Trạng thái sân đã được cập nhật thành công", null, result);
                }
                else
                {
                    response = ResponseModel <FieldDetailViewModel> .CreateErrorResponse("Cập nhật trạng thái sân thất bại", systemError);
                }
            }
            catch (Exception)
            {
                response = ResponseModel <FieldDetailViewModel> .CreateErrorResponse("Cập nhật trạng thái sân thất bại", systemError);
            }

            return(Json(response));
        }
        public ActionResult ShowFieldDetail(int id)
        {
            ResponseModel <FieldDetailViewModel> response = null;

            var service = this.Service <IFieldService>();

            try
            {
                Field field = service.GetFieldInfo(id);
                if (field != null)
                {
                    FieldDetailViewModel result = PrepareFieldDetailViewModel(field);

                    response = new ResponseModel <FieldDetailViewModel>(true, "Chi tiết sân:", null, result);
                }
                else
                {
                    response = ResponseModel <FieldDetailViewModel> .CreateErrorResponse("Tải chi tiết sân thất bại!", systemError);
                }
            }
            catch (Exception)
            {
                response = ResponseModel <FieldDetailViewModel> .CreateErrorResponse("Tải chi tiết sân thất bại!", systemError);
            }

            return(Json(response));
        }
Esempio n. 3
0
        public ActionResult FieldDetail(string name, string target, string cntl, string actn, string currFld)
        {
            FieldDetailViewModel fvm = new FieldDetailViewModel();

            fvm.target    = target;
            fvm.actn      = actn;
            fvm.cntl      = cntl;
            fvm.currFld   = currFld;
            fvm.placehldr = _sd.GetUserPrompt("fieldcommentplaceholder");

            if (!string.IsNullOrEmpty(name))
            {
                Field fld = _ud.GetFieldDetails(name);
                fvm.currFieldName = fld.fieldName;
                fvm.fieldName     = fld.fieldName;
                fvm.fieldArea     = fld.area.ToString();
                fvm.fieldComment  = fld.comment;
                fvm.fieldId       = fld.id;
                fvm.act           = "Edit";
            }
            else
            {
                fvm.act = "Add";
            }
            return(PartialView("FieldDetail", fvm));
        }
Esempio n. 4
0
 private FieldDetailWindow()
 {
     _vmField = new FieldDetailViewModel()
     {
         Window = this
     };
     this.DataContext = _vmField;
     this.AddModel(_vmField);
     InitializeComponent();
 }
        private FieldDetailViewModel PrepareFieldDetailViewModel(Field field)
        {
            FieldDetailViewModel result = Mapper.Map <FieldDetailViewModel>(field);

            result.StatusString = Utils.GetEnumDescription((FieldStatus)result.Status);

            FieldImage image = field.FieldImages.FirstOrDefault();

            if (image != null)
            {
                result.Avatar = image.Image;
            }
            return(result);
        }
Esempio n. 6
0
        public ActionResult FieldDetail(string name, string target, string cntl, string actn, string currFld)
        {
            FieldDetailViewModel fvm = new FieldDetailViewModel();

            Models.StaticData.ConversionFactor cf = _sd.GetConversionFactor();

            fvm.selPrevYrManureOptions = _sd.GetPrevManureApplicationInPrevYears();

            fvm.target    = target;
            fvm.actn      = actn;
            fvm.cntl      = cntl;
            fvm.currFld   = currFld;
            fvm.placehldr = _sd.GetUserPrompt("fieldcommentplaceholder");

            if (!string.IsNullOrEmpty(name))
            {
                Field fld = _ud.GetFieldDetails(name);
                fvm.currFieldName = fld.fieldName;
                fvm.fieldName     = fld.fieldName;
                fvm.fieldArea     = fld.area.ToString();
                fvm.fieldComment  = fld.comment;
                fvm.fieldId       = fld.id;
                // retrofit old saved NMP files
                if (String.IsNullOrEmpty(fld.prevYearManureApplicationFrequency))
                {
                    // set to default (no manure applied in the last two years)
                    fvm.selPrevYrManureOption = cf.defaultApplicationOfManureInPrevYears;
                }
                else
                {
                    fvm.selPrevYrManureOption = fld.prevYearManureApplicationFrequency;
                }
                fvm.act = "Edit";
            }
            else
            {
                fvm.act = "Add";
            }
            return(PartialView("FieldDetail", fvm));
        }
Esempio n. 7
0
        public ActionResult FieldDetail(FieldDetailViewModel fvm)
        {
            decimal area = 0;
            string  url;

            // required to populate o/w validation messages are suppressed
            fvm.selPrevYrManureOptions = _sd.GetPrevManureApplicationInPrevYears();

            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(fvm.fieldComment))
                {
                    if (fvm.fieldComment.Length > Convert.ToInt32(_appSettings.Value.CommentLength))
                    {
                        ModelState.AddModelError("fieldComment", "Comment length of " + fvm.fieldComment.Length.ToString() + " exceeds maximum of " + _appSettings.Value.CommentLength);
                        return(PartialView("FieldDetail", fvm));
                    }
                }
                try
                {
                    area = decimal.Parse(fvm.fieldArea);
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("fieldArea", "Invalid amount for area.");
                    return(PartialView("FieldDetail", fvm));
                }
                if (fvm.selPrevYrManureOption == "select")
                {
                    ModelState.AddModelError("selPrevYrManureOption", "Manure application in previous years must be selected");
                    return(PartialView("FieldDetail", fvm));
                }

                Field fld = _ud.GetFieldDetails(fvm.fieldName);

                if (fld != null)
                {
                    if ((fvm.act == "Edit" & fvm.currFieldName != fvm.fieldName) |
                        fvm.act == "Add")
                    {
                        ModelState.AddModelError("fieldName", "A field already exists with this name.");
                        return(PartialView("FieldDetail", fvm));
                    }
                }

                if (fvm.act == "Add")
                {
                    fld = new Field();
                }
                else
                {
                    fld = _ud.GetFieldDetails(fvm.currFieldName);
                    if (fld == null)
                    {
                        fld = new Field();
                    }
                }

                fld.fieldName = fvm.fieldName;
                fld.area      = Math.Round(area, 1);
                fld.comment   = fvm.fieldComment;
                fld.prevYearManureApplicationFrequency = fvm.selPrevYrManureOption;

                if (fvm.act == "Add")
                {
                    _ud.AddField(fld);
                }
                else
                {
                    _ud.UpdateField(fld);
                }
                if (fvm.target == "#fields")
                {
                    url = Url.Action("RefreshFieldsList", "Fields");
                }
                else
                {
                    url = Url.Action(fvm.actn, fvm.cntl, new { nme = fld.fieldName });

                    //url = Url.Action("RefreshList", "Fields", new { cntl = fvm.cntl, actn = fvm.actn, currFld = fvm.currFld });
                }
                return(Json(new { success = true, url = url, target = fvm.target }));
            }
            return(PartialView("FieldDetail", fvm));
        }
Esempio n. 8
0
        public ActionResult FieldDetail(FieldDetailViewModel fvm)
        {
            decimal area = 0;
            string  url;

            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(fvm.fieldComment))
                {
                    if (fvm.fieldComment.Length > Convert.ToInt32(_appSettings.Value.CommentLength))
                    {
                        ModelState.AddModelError("fieldComment", "Comment length of " + fvm.fieldComment.Length.ToString() + " exceeds maximum of " + _appSettings.Value.CommentLength);
                        return(PartialView("FieldDetail", fvm));
                    }
                }
                try
                {
                    area = decimal.Parse(fvm.fieldArea);
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("fieldArea", "Invalid amount for area.");
                    return(PartialView("FieldDetail", fvm));
                }

                Field fld = _ud.GetFieldDetails(fvm.fieldName);

                if (fld != null)
                {
                    if ((fvm.act == "Edit" & fvm.currFieldName != fvm.fieldName) |
                        fvm.act == "Add")
                    {
                        ModelState.AddModelError("fieldName", "A field already exists with this name.");
                        return(PartialView("FieldDetail", fvm));
                    }
                }

                if (fvm.act == "Add")
                {
                    fld = new Field();
                }
                else
                {
                    fld = _ud.GetFieldDetails(fvm.currFieldName);
                    if (fld == null)
                    {
                        fld = new Field();
                    }
                }

                fld.fieldName = fvm.fieldName;
                fld.area      = Math.Round(area, 1);
                fld.comment   = fvm.fieldComment;

                if (fvm.act == "Add")
                {
                    _ud.AddField(fld);
                }
                else
                {
                    _ud.UpdateField(fld);
                }
                if (fvm.target == "#fields")
                {
                    url = Url.Action("RefreshFieldsList", "Fields");
                }
                else
                {
                    url = Url.Action("RefreshList", "Fields", new { cntl = fvm.cntl, actn = fvm.actn, currFld = fvm.currFld });
                }
                return(Json(new { success = true, url = url, target = fvm.target }));
            }
            return(PartialView("FieldDetail", fvm));
        }