Esempio n. 1
0
        public ActionResult NewDoc(int id, DocumentCreateForm collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    DocumentService d      = new DocumentService();
                    BinService      b      = new BinService();
                    byte[]          buffer = new byte[collection.FileBinary.ContentLength];
                    collection.FileBinary.InputStream.Read(buffer, 0, collection.FileBinary.ContentLength);
                    Bin fileBin = new Bin()
                    {
                        Binaries   = buffer,
                        UploadName = collection.FileBinary.FileName
                    };
                    fileBin = b.Insert(fileBin);

                    Document doc = new Document(collection.Name, collection.Description, collection.ModifiedDate, collection.Size, collection.Extention, UserSession.CurrentUser.Id, fileBin.Id, null);
                    doc = d.Insert(doc);
                    if (!d.InsertToTask(doc, id))
                    {
                        /*-----------If don't have receiver, don't saved in DB------------*/
                        //b.Delete(fileBin.Id);
                        //d.Delete(doc.Id);
                    }
                }
                return(RedirectToAction("Details", new { id = id }));
            }
            catch
            {
                return(RedirectToAction("Details", new { id = id }));
            }
        }
Esempio n. 2
0
        public ActionResult Create(DocumentCreateForm collection)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    DocumentService d      = new DocumentService();
                    BinService      b      = new BinService();
                    byte[]          buffer = new byte[collection.FileBinary.ContentLength];
                    collection.FileBinary.InputStream.Read(buffer, 0, collection.FileBinary.ContentLength);
                    Bin fileBin = new Bin()
                    {
                        Binaries   = buffer,
                        UploadName = collection.FileBinary.FileName
                    };
                    fileBin = b.Insert(fileBin);

                    Document doc = new Document(collection.Name, collection.Description, collection.ModifiedDate, collection.Size, collection.Extention, UserSession.CurrentUser.Id, fileBin.Id, null);
                    doc = d.Insert(doc);
                    switch (collection.Kind)
                    {
                    case "Task":
                        //procedure task
                        d.InsertToTask(doc, collection.ReceiverId);
                        break;

                    case "Project":
                        //procedure project
                        d.InsertToProject(doc, collection.ReceiverId);
                        break;

                    case "Team":
                        //procedure team
                        d.InsertToTeam(doc, collection.ReceiverId);
                        break;

                    case "Department":
                        //procedure department
                        d.InsertToDepartment(doc, collection.ReceiverId);
                        break;

                    case "Event":
                        //procedure Event
                        d.InsertToEvent(doc, collection.ReceiverId);
                        break;

                    default:
                        /*-----------If don't have receiver, don't saved in DB------------*/
                        //b.Delete(fileBin.Id);
                        //d.Delete(doc.Id);
                        return(View(collection));
                    }
                    return(RedirectToAction("Details", new { id = doc.Id }));
                }
                return(View(collection));
            }
            catch
            {
                return(View(collection));
            }
        }