Esempio n. 1
0
        public async Task <object> Post([FromBody] CooperationViewModel model)
        {
            MessageBase2 result = new MessageBase2();

            CooperationDto dto = ConvertHelper.ChangeType <CooperationDto>(model);
            await _cooperationService.AddAsync(dto);

            return(result);
        }
Esempio n. 2
0
        public ActionResult Create(CooperationViewModel cooperationViewModel)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                int userId = Com.Cos.Common.Public.GetLoginUid();

                Com.Cos.Models.Cooperation cooperation = new Com.Cos.Models.Cooperation
                {
                    UserId      = userId.ToString(),
                    Title       = cooperationViewModel.Title,
                    EnrollEnd   = cooperationViewModel.EnrollEnd,
                    Address     = cooperationViewModel.Address,
                    Cont        = cooperationViewModel.Cont,
                    RMBBudget   = cooperationViewModel.Budget,
                    ImgList     = cooperationViewModel.ImgList,
                    Cover       = cooperationViewModel.Cover,
                    Will        = cooperationViewModel.Will,
                    ReleaseTime = DateTime.Now,
                    Status      = 1
                };
                cooperation = _cooperationService.Add(cooperation);
                if (cooperation.Id > 0)
                {
                    return(Json(new Dictionary <string, string>()
                    {
                        { "status", "success" }, { "message", "发布成功" }
                    }));
                }
                return(Json(new Dictionary <string, string>()
                {
                    { "status", "error" }, { "message", "发布失败" }
                }));
            }
            string error = errors.ToArray()[0].ErrorMessage;

            return(Json(new Dictionary <string, string>()
            {
                { "status", "error" }, { "message", $"{error}" }
            }));
        }