Exemple #1
0
        private int SaveAttachedFiles(string[] FileNames, int CuttingSheetId)
        {
            int savefiles = 0;
            CuttingSheetFile CuttingSheetFile = new CuttingSheetFile();

            if (FileNames != null)
            {
                foreach (string FileName in FileNames)
                {
                    string st = "_CuttingSheet " + FileName;
                    CuttingSheetFile.CuttingSheetId = CuttingSheetId;
                    CuttingSheetFile.Name           = FileName;
                    CuttingSheetFile.Path           = Path.Combine(Server.MapPath(FolderPath.FolderPathCustomerDoc), st);
                    try
                    {
                        db.CuttingSheetFiles.Add(CuttingSheetFile);
                        db.SaveChanges();
                        savefiles = 1;
                    }
                    catch (Exception e)
                    {
                        ViewBag.Error += "Files not saved :" + e.Message;
                        log.Error(" ERROR mylog - Error while save  file of project " + CuttingSheetId + ":" + e.Message + " , stacktrace:" + e.StackTrace);
                    }
                }
            }
            return(savefiles);
        }
Exemple #2
0
        private void RemoveFiles(int cuttingSheetId)
        {
            CuttingSheet cuttingSheet = db.CuttingSheets.Include(c => c.CuttingSheetFiles).Where(c => c.CuttingSheetId == cuttingSheetId).FirstOrDefault();

            if (cuttingSheet.CuttingSheetFiles.Count() > 0)
            {
                foreach (var file in cuttingSheet.CuttingSheetFiles.ToList())
                {
                    CuttingSheetFile cuttingSheetFiles = db.CuttingSheetFiles.Find(file.CuttingSheetFileId);
                    db.CuttingSheetFiles.Remove(cuttingSheetFiles);
                }
                db.SaveChanges();
            }
        }
Exemple #3
0
        public JsonResult CreateJson([Bind(Include = "CuttingSheetId,ProjectId,UserCreate,CreateDate,code")] CuttingSheet cuttingSheet,
                                     String[] FileName)
        {
            int savefiles = 0;

            if (ModelState.IsValid)
            {
                if (FileName != null && FileName.Count() > 0)
                {
                    try
                    {
                        //change status of project
                        if (cuttingSheet.ProjectId != null)
                        {
                            var proj = db.Projects.Find(cuttingSheet.ProjectId);
                            proj.ProjectStatusId = 4;
                        }
                        cuttingSheet.StampDate  = DateTime.Now;
                        cuttingSheet.UserCreate = User.Identity.GetUserName();
                        db.CuttingSheets.Add(cuttingSheet);
                        db.SaveChanges();

                        this.notificationRepository.CreateNotificationAsync(cuttingSheet.CuttingSheetId, NotificationName.onCreateMRF);


                        //file link
                        //save uploaded files record
                        CuttingSheetFile CuttingSheetFile = new CuttingSheetFile();
                        if (FileName != null)
                        {
                            foreach (string fn in FileName)
                            {
                                string st = "_CuttingSheet " + fn;
                                CuttingSheetFile.CuttingSheetId = cuttingSheet.CuttingSheetId;
                                //String c = db.Customers.Find(contract.CustomerId).CompanyName;

                                CuttingSheetFile.Name = fn;
                                CuttingSheetFile.Path = Path.Combine(Server.MapPath(FolderPath.FolderPathCustomerDoc), st);



                                try
                                {
                                    db.CuttingSheetFiles.Add(CuttingSheetFile);
                                    db.SaveChanges();

                                    savefiles = 1;
                                }
                                catch (Exception e)
                                {
                                    ViewBag.Error += "Files not saved :" + e.Message;
                                    log.Error(" ERROR mylog - Error while save  file of project " + cuttingSheet.CuttingSheetId + ":" + e.Message + " , stacktrace:" + e.StackTrace);
                                }
                            }
                        }



                        return(Json(cuttingSheet.CuttingSheetId));
                    }
                    catch (Exception ex)
                    {
                        String errors11 = ex.Message;

                        if (ex.InnerException != null)
                        {
                            errors11 = errors11 + ex.InnerException.Message + " \r\n ";;
                        }
                        return(Json(errors11));
                    }
                }
                else
                {
                    string Error = "Please upload Production Sheet";
                    return(Json(Error));
                }
            }
            return(Json("errors11"));
        }