public bool Post([FromBody] CarTB cartb) { try { var output = (from Cars in _DatabaseContext.CarTB where Cars.Model_Name == cartb.Model_Name && Cars.Brand == cartb.Brand select Cars.Brand).Count(); if (output > 0) { return(false); } else { var UserID = (from user in _DatabaseContext.UserMasterTB where user.Username == cartb.Username select user.U_Id).SingleOrDefault(); cartb.C_Id = 0; cartb.UserID = UserID; cartb.CreatedOn = DateTime.Now; _DatabaseContext.Add(cartb); _DatabaseContext.SaveChanges(); return(true); } } catch (Exception) { throw; } }
public bool Post([FromBody] CarTB cartb) { try { if (string.IsNullOrEmpty(cartb.Model_Name)) { return(false); } var output = (from car in _DatabaseContext.CarTB where car.Model_Name == cartb.Model_Name select car.Model_Name).Count(); if (output > 0) { return(false); } else { return(true); } } catch (Exception) { throw; } }
public JsonResult UploadFiles([FromHeader] ReceiverClass ReceiverClass) { try { if (string.IsNullOrEmpty(ReceiverClass.SelectedCarID)) { return(Json(false)); } var files = HttpContext.Request.Form.Files; string PathDB = string.Empty; if (files == null) { return(Json(false)); } var C_Id = Convert.ToInt32(ReceiverClass.SelectedCarID); var uploads = Path.Combine(_environment.WebRootPath, "Cars_Upload"); foreach (var file in files) { if (file.Length > 0) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var myUniqueFileName = Convert.ToString(Guid.NewGuid()); var FileExtension = Path.GetExtension(fileName); var newFileName = myUniqueFileName + FileExtension; fileName = Path.Combine(_environment.WebRootPath, "Cars_Upload") + $@"\{newFileName}"; PathDB = "Cars_Upload/" + newFileName; using (FileStream fs = System.IO.File.Create(fileName)) { file.CopyTo(fs); fs.Flush(); } } } var cartb = new CarTB { C_Id = C_Id, Image = PathDB }; var db = _DatabaseContext; db.CarTB.Attach(cartb); db.Entry(cartb).Property(x => x.Image).IsModified = true; db.SaveChanges(); return(Json(true)); } catch (Exception) { throw; } }
public bool Put(int id, [FromBody] CarTB cartb) { try { if (string.IsNullOrEmpty(Convert.ToString(id))) { return(false); } if (cartb == null) { return(false); } var carupdate = new CarTB { C_Id = cartb.C_Id, Model_Name = cartb.Model_Name, Brand = cartb.Brand, Color = cartb.Color, Fueltype = cartb.Fueltype, No_of_Pas = cartb.No_of_Pas, Price = cartb.Price }; var db = _DatabaseContext; db.CarTB.Attach(carupdate); db.Entry(carupdate).Property(x => x.Model_Name).IsModified = true; db.Entry(carupdate).Property(x => x.Brand).IsModified = true; db.Entry(carupdate).Property(x => x.Color).IsModified = true; db.Entry(carupdate).Property(x => x.Fueltype).IsModified = true; db.Entry(carupdate).Property(x => x.No_of_Pas).IsModified = true; db.Entry(carupdate).Property(x => x.Price).IsModified = true; db.SaveChanges(); return(true); } catch (Exception) { throw; } }