public ActionResult CreatePhone(PhoneViewModel phoneViewModel, HttpPostedFileBase uploadImage)
        {
            try
            {
                if (ModelState.IsValid && uploadImage != null)
                {
                    byte[] imageData = null;

                    using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                    {
                        imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                    }

                    PhoneDto phoneDto = MappingPhoneViewModelToPhoneDto(phoneViewModel);
                    phoneDto.Image = imageData;
                    int phoneId = phoneService.Create(phoneDto);

                    return(RedirectToAction("CreatePhoneSuccess", new { phoneId }));
                }
                return(View(phoneViewModel));
            }
            catch (ValidationException ex)
            {
                return(Content(ex.Message));
            }
        }
示例#2
0
        public void Create(int id)
        {
            Console.WriteLine("Input phone number: ");
            phone newPhone = new phone()
            {
                number = Console.ReadLine(), type = "home", personId = id
            };

            _phoneService.Create(newPhone);
        }
示例#3
0
 public HttpResponseMessage AddFollower(FollowerModel followerModel)
 {
     if (followerModel != null)
     {
         var followerentity = new FollowerEntity
         {
             Openid        = followerModel.Openid,
             Nickname      = followerModel.Nickname,
             Sex           = followerModel.Sex,
             City          = followerModel.City,
             Country       = followerModel.Country,
             Private       = followerModel.Private,
             Language      = followerModel.Language,
             Headimgurl    = followerModel.Headimgurl,
             Subscribetime = followerModel.Subscribe_time,
             Unioid        = followerModel.Unioid,
             Remark        = followerModel.Remark,
             Groupid       = followerModel.Groupid,
             Adduser       = followerModel.Adduser,
             Addtime       = DateTime.Now,
             Upuser        = followerModel.Upuser,
             Uptime        = DateTime.Now
         };
         var phoneentity = new PhoneEntity
         {
             Follower = _followerService.Create(followerentity),
             Openid   = followerModel.Openid,
             Phone    = followerModel.Phone,
             Adduser  = followerModel.Adduser,
             Addtime  = DateTime.Now,
             Upuser   = followerModel.Upuser,
             Uptime   = DateTime.Now
         };
         try
         {
             _phoneService.Create(phoneentity);
             return(PageHelper.toJson(PageHelper.ReturnValue(true, "数据添加成功!")));
         }
         catch
         {
             return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据添加失败!")));
         }
     }
     return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误!")));
 }
示例#4
0
 public void Post([FromBody] Phone phone)
 {
     phoneService.Create(phone);
 }