public long Save(SketchMaster master) { if (master.SketchId == 0) { db.SketchMasters.Add(master); } db.SaveChanges(); return(master.SketchId); }
public dynamic Save(SketchFile file) { try { string userId = file.UserId[0]; string fileName = file.FileName[0]; string filePath = Server.MapPath("~/DataSketchFile"); String userIdPath = filePath + "\\" + userId; //If no any such directory then creates the new one if (!Directory.Exists(userIdPath)) { Directory.CreateDirectory(filePath + "\\" + userId); } string fileFullPath = filePath + "\\" + userId + "\\" + fileName + ".txt"; FileInfo sketchFileInfo = new FileInfo(fileFullPath); // Check if file already exists. If yes, delete it. if (sketchFileInfo.Exists) { sketchFileInfo.Delete(); } // Create a new file using (StreamWriter sw = sketchFileInfo.CreateText()) { sw.Write(file.FileContent[0]); sw.Dispose(); } SketchMasterEntity sketchMasterentity = new SketchMasterEntity(); SketchMaster sketchMaster = sketchMasterentity.Create(); SketchMaster checkRecord = sketchMasterentity.checkRecord(Convert.ToInt32(userId), fileName); if (checkRecord == null) { sketchMaster.IsActive = true; sketchMaster.IsDelete = false; sketchMaster.SketchName = fileName; sketchMaster.SketchPath = fileName + ".txt"; sketchMaster.UserId = Convert.ToInt32(userId); sketchMaster.CreatedBy = Convert.ToInt32(userId); sketchMaster.CreatedOn = DateTime.Now; sketchMaster.UpdatedBy = null; sketchMaster.UpdatedOn = null; sketchMasterentity.Save(sketchMaster); } } catch (Exception ex) { return(false); } return(string.Empty); }
public static SketchMasterModel Mapping(SketchMaster db) { SketchMasterModel model = new SketchMasterModel(); model.SketchId = db.SketchId; model.SketchName = db.SketchName; model.SketchPath = db.SketchPath; model.UserId = db.UserId; model.IsActive = db.IsActive; model.IsDelete = db.IsDelete; model.CreatedBy = db.CreatedBy; model.CreatedOn = db.CreatedOn; model.UpdatedBy = db.UpdatedBy; model.UpdatedOn = db.UpdatedOn; return(model); }