public ProductitemInfo Save() { if (this.Id != null) { Productitem.Update(this); return(this); } return(Productitem.Insert(this)); }
public APIReturn _Edit([FromQuery] uint Id, [FromForm] uint?Product_id, [FromForm] string Img_url, [FromForm] IFormFile Img_url_file, [FromForm] string Name, [FromForm] decimal?Original_price, [FromForm] decimal?Price, [FromForm] uint?Stock) { ProductitemInfo item = Productitem.GetItem(Id); if (item == null) { return(APIReturn.记录不存在_或者没有权限); } if (!string.IsNullOrEmpty(item.Img_url) && (item.Img_url != Img_url || Img_url_file != null)) { string path = System.IO.Path.Combine(AppContext.BaseDirectory, item.Img_url); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } if (Img_url_file != null) { item.Img_url = $"/upload/{Guid.NewGuid().ToString()}.png"; using (FileStream fs = new FileStream(System.IO.Path.Combine(AppContext.BaseDirectory, item.Img_url), FileMode.Create)) Img_url_file.CopyTo(fs); } else { item.Img_url = Img_url; } item.Product_id = Product_id; item.Name = Name; item.Original_price = Original_price; item.Price = Price; item.Stock = Stock; int affrows = Productitem.Update(item); if (affrows > 0) { return(APIReturn.成功.SetMessage($"更新成功,影响行数:{affrows}")); } return(APIReturn.失败); }