Exemplo n.º 1
0
 public Order Put(long customerId, PutModel input)
 {
     if (!input.ProductID.HasValue)
     {
         return(orderComponent.UpdateQuantity(customerId, input.Quantity));
     }
     return(orderComponent.UpdateProduct(customerId, input.ProductID.Value, input.Quantity));
 }
Exemplo n.º 2
0
 public async Task Put(Guid id, [FromBody] PutModel model)
 {
     await _todoItemService.Update(new UpdateModel
     {
         Id          = id,
         Description = model.Description,
         DueDate     = model.DueDate
     });
 }
Exemplo n.º 3
0
        public void Post([FromBody] PutModel data)
        {
            var value = data.name;

            initUser();
            var _user = _context.Users.First <ApplicationUser>(u => u.Id == _user_id);
            var added = new Board {
                createDate = DateTime.Now, modifyDate = DateTime.Now, id = Guid.NewGuid(), name = value, user = _user
            };

            _context.Add(added);
            _context.SaveChanges();
        }
        public static UpdateWithBodyDto ToDto(this PutModel model)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            return(new UpdateWithBodyDto(
                       Name: model.Name,
                       Subject: model.Subject,
                       IsHtml: model.IsHtml,
                       Type: model.Type,
                       Body: model.Body));
        }
Exemplo n.º 5
0
        public void Put_Orders_Products_With_CustomerID()
        {
            var      controller = GetController();
            PutModel putModel   = new PutModel();

            putModel.ProductID = 1;
            putModel.Quantity  = 10;

            controller.Get(1);
            var result = controller.Put(1, putModel);


            Assert.True(result.Products.Count == 1);
            Assert.Equal(10, result.Products[0].Quantity);
        }
        public static UpdateDto ToDto(this PutModel model, SecretDoc?secret)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            return(new UpdateDto(
                       Name: model.Name,
                       Secret: secret,
                       RequireEmailVerification: model.RequireEmailVerification,
                       VerifyAccountEmailTemplateId: model.VerifyAccountEmailTemplateId,
                       PasswordResetEmailTemplateId: model.PasswordResetEmailTemplateId,
                       AuthorityUrl: model.AuthorityUrl,
                       PortalUrl: model.PortalUrl));
        }
Exemplo n.º 7
0
        public ActionResult AddColumnToBoardById(Guid id, [FromBody] PutModel data)
        {
            var value = data.name;

            initUser();
            Board candidateBoard = _context.Boards
                                   .Include(board => board.Columns)
                                   .Where(board => board.id == id && board.user.Id == _user_id)
                                   .FirstOrDefault();

            if (candidateBoard is not null)
            {
                if (candidateBoard.Columns is null)
                {
                    candidateBoard.Columns = new List <Column>();
                }
                var _user = _context.Users.First <ApplicationUser>(u => u.Id == _user_id);
                var added = new Column
                {
                    BoardId    = candidateBoard.id,
                    order      = candidateBoard.Columns.Count() + 1,
                    createDate = DateTime.Now,
                    modifyDate = DateTime.Now,
                    name       = value,
                    user       = _user
                };
                candidateBoard.Columns.Add(added);
                candidateBoard.modifyDate = DateTime.Now;
                _context.Entry <Board>(candidateBoard).State = EntityState.Modified;
                try
                {
                    var success = _context.SaveChanges();
                    return(Ok(success));
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
            return(NotFound(id));
        }
Exemplo n.º 8
0
        static async Task CallPutCart()
        {
            using (var client = new HttpClient())
            {
                PutModel putModel = new PutModel {
                    ProductID = 2, Quantity = 10
                };

                client.BaseAddress = new Uri(ConfigurationManager.AppSettings["BaseAddress"]);
                client.DefaultRequestHeaders.Accept.Clear();

                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                //Get Method

                //JsonAsync("api/Cart/1", putModel);
                var items = new Dictionary <string, string>();
                items.Add("ProductId", "2");
                items.Add("Quantity", "10");
                FormUrlEncodedContent content  = new FormUrlEncodedContent(items);
                HttpResponseMessage   response = await client.PutAsync("api/Cart/1", content);

                if (response.IsSuccessStatusCode)
                {
                    var order = await response.Content.ReadAsAsync <Order>();

                    Console.WriteLine($" Order ID : { order.ID} , Order Name : {order.Status} , Customer ID : {order.CustomerID}");

                    foreach (var item in order.Products)
                    {
                        Console.WriteLine($" Product ID : { item.ProductID} , Total Price : {item.TotalPrice} , Quantity  : {item.Quantity}");
                    }
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("internal server error");
                    Console.ReadKey();
                }
            }
        }
Exemplo n.º 9
0
        public ActionResult Put(Guid id, [FromBody] PutModel data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }
            initUser();

            var currBoard = _context.Boards
                            .Include(board => board.Columns.OrderBy(c => c.order))
                            .FirstOrDefault <Board>(board => board.id == id && board.user.Id == _user_id);

            if (currBoard is not null)
            {
                try
                {
                    currBoard.name       = data.board.name;
                    currBoard.modifyDate = DateTime.Now;
                    for (var i = 0; i < currBoard.Columns.Count(); i++)
                    {
                        var currCol = currBoard.Columns[i];
                        var inCol   = data.board.Columns.Where(varcol => varcol.id == currCol.id).FirstOrDefault();
                        currCol.order      = inCol.order;
                        currCol.modifyDate = DateTime.Now;
                    }

                    var success = _context.SaveChanges();
                    return(Ok(success));
                }
                catch (Exception er)
                {
                    return(Ok(er.Message));
                }
            }
            return(NotFound(id));
        }
Exemplo n.º 10
0
 public PutRequest(ObjectId templateId, PutModel model)
 {
     TemplateId = templateId;
     Model      = model ?? throw new ArgumentNullException(nameof(model));
 }
Exemplo n.º 11
0
        public async Task <NoContentResult> PutAsync([FromBody] PutModel model, CancellationToken cancellationToken)
        {
            await fSender.Send(new PutRequest(model), cancellationToken);

            return(NoContent());
        }
        public async Task <IActionResult> PutAsync([FromRoute] ObjectId id, [FromBody] PutModel model, CancellationToken cancellationToken)
        {
            await fSender.Send(new PutRequest(id, model), cancellationToken);

            return(NoContent());
        }
Exemplo n.º 13
0
 public PutRequest(ObjectId clientId, PutModel model)
 {
     ClientId = clientId;
     Model    = model ?? throw new ArgumentNullException(nameof(model));
 }
Exemplo n.º 14
0
        public HttpResponseMessage Post([FromBody] PutModel value)
        {
            HttpResponseMessage result = null;
            var    appSettings         = ConfigurationManager.AppSettings;
            string SourcePath          = appSettings["CourseDirectory"] + value.source;
            string TargetPath          = appSettings["CourseDirectory"] + value.target;

            if (value.action == "CourseVideoMove")
            {
                StringBuilder sb = new StringBuilder();
                StringWriter  sw = new StringWriter(sb);
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    writer.Formatting = Formatting.Indented;
                    writer.WriteStartObject();
                    //video+pic
                    writer.WritePropertyName("video");
                    if (File.Exists(SourcePath + value.ProjectId + ".mp4") && File.Exists(SourcePath + value.ProjectId + ".jpg"))
                    {
                        //建目录
                        if (Directory.Exists(TargetPath))
                        {
                            if (File.Exists(TargetPath + @"raw.mp4"))
                            {
                                File.Delete(TargetPath + @"raw.mp4");
                            }
                            if (File.Exists(TargetPath + @"rip.mp4"))
                            {
                                File.Delete(TargetPath + @"rip.mp4");
                            }
                            if (File.Exists(TargetPath + @"raw.jpg"))
                            {
                                File.Delete(TargetPath + @"raw.jpg");
                            }
                        }
                        else
                        {
                            Directory.CreateDirectory(TargetPath);
                        }
                        File.Move(SourcePath + value.ProjectId + ".mp4", TargetPath + "raw.mp4");
                        writer.WriteValue("1");
                        //pic
                        writer.WritePropertyName("pic");
                        File.Move(SourcePath + value.ProjectId + ".jpg", TargetPath + "raw.jpg");
                        writer.WriteValue("1");
                        //doc
                        writer.WritePropertyName("doc");
                        if (File.Exists(SourcePath + value.ProjectId + ".zip"))
                        {
                            if (File.Exists(TargetPath + @"slide0.zip"))
                            {
                                File.Delete(TargetPath + @"slide0.zip");
                            }
                            File.Move(SourcePath + value.ProjectId + ".zip", TargetPath + "slide0.zip");
                            writer.WriteValue("1");
                        }
                        else
                        {
                            writer.WriteValue("0");
                        }
                    }
                    else
                    {
                        writer.WriteValue("0");
                    }
                    writer.WriteEnd();
                    //writer.WriteEndObject();
                }
                result         = new HttpResponseMessage(HttpStatusCode.Accepted);
                result.Content = new StringContent(sb.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json");
            }
            else if (value.action == "CourseFileCopy")
            {
                StringBuilder sb = new StringBuilder();
                StringWriter  sw = new StringWriter(sb);
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    writer.Formatting = Formatting.Indented;
                    writer.WriteStartObject();
                    //video+pic
                    writer.WritePropertyName("video");
                    if (File.Exists(SourcePath + "raw" + ".mp4") && File.Exists(SourcePath + "raw" + ".jpg"))
                    {
                        //建目录
                        if (Directory.Exists(TargetPath))
                        {
                            if (File.Exists(TargetPath + @"raw.mp4"))
                            {
                                File.Delete(TargetPath + @"raw.mp4");
                            }
                            if (File.Exists(TargetPath + @"rip.mp4"))
                            {
                                File.Delete(TargetPath + @"rip.mp4");
                            }
                            if (File.Exists(TargetPath + @"raw.jpg"))
                            {
                                File.Delete(TargetPath + @"raw.jpg");
                            }
                        }
                        else
                        {
                            Directory.CreateDirectory(TargetPath);
                        }
                        File.Copy(SourcePath + "raw" + ".mp4", TargetPath + "raw.mp4");
                        writer.WriteValue("1");
                        //pic
                        writer.WritePropertyName("pic");
                        File.Copy(SourcePath + "raw" + ".jpg", TargetPath + "raw.jpg");
                        writer.WriteValue("1");
                        //doc
                        writer.WritePropertyName("doc");
                        if (File.Exists(SourcePath + "slide0" + ".zip"))
                        {
                            if (File.Exists(TargetPath + @"slide0.zip"))
                            {
                                File.Delete(TargetPath + @"slide0.zip");
                            }
                            File.Copy(SourcePath + "slide0" + ".zip", TargetPath + "slide0.zip");
                            writer.WriteValue("1");
                        }
                        else
                        {
                            writer.WriteValue("0");
                        }
                    }
                    else
                    {
                        writer.WriteValue("0");
                    }
                    writer.WriteEnd();
                    //writer.WriteEndObject();
                }
                result         = new HttpResponseMessage(HttpStatusCode.Accepted);
                result.Content = new StringContent(sb.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json");
            }
            else if (value.action == "JsonBackup")
            {
                StringBuilder sb = new StringBuilder();
                StringWriter  sw = new StringWriter(sb);
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    writer.Formatting = Formatting.Indented;
                    writer.WriteStartObject();
                    writer.WritePropertyName("json");
                    if (File.Exists(SourcePath + "captions.json"))
                    {
                        try
                        {
                            File.Copy(SourcePath + "captions.json", SourcePath + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_") + "captions_backup.json");
                            File.Copy(SourcePath + "captions_auto.json", SourcePath + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_") + "captions_auto_backup.json");
                        }
                        catch (Exception e)
                        {
                            result         = new HttpResponseMessage(HttpStatusCode.Accepted);
                            result.Content = new StringContent(e.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json");
                        }
                        writer.WriteValue("1");
                    }
                    else
                    {
                        writer.WriteValue("0");
                    }
                    writer.WriteEnd();
                }
                result         = new HttpResponseMessage(HttpStatusCode.Accepted);
                result.Content = new StringContent(sb.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json");
            }
            else if (value.action == "CourseDirectoryRename")
            {
            }
            else
            {
            }
            return(result);
        }
Exemplo n.º 15
0
 public PutRequest(PutModel model)
 {
     Model = model ?? throw new System.ArgumentNullException(nameof(model));
 }