Example #1
0
        public async Task <ActionResult> Create(ProductView view)
        {
            if (ModelState.IsValid)
            {
                var picture = string.Empty;
                var folder  = "~/Content/Products";
                if (view.ImageFile != null)
                {
                    picture = FilesHelpers.UploadPhoto(view.ImageFile, folder);
                    picture = $"{folder}/{picture}";
                }

                var product = this.ToProduct(view, picture);

                try
                {
                    db.Products.Add(product);
                    await db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                }
                return(RedirectToAction("Index"));
            }

            return(View(view));
        }
Example #2
0
        public ActionResult Create(Product product)
        {
            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();

                if (product.ImageFile != null)
                {
                    var folder  = "~/Content/Products";
                    var file    = string.Format("{0}-{1}.jpg", product.ProductId, product.Description);
                    var respose = FilesHelpers.UploadPhoto(product.ImageFile, folder, file);

                    if (respose)
                    {
                        var pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        product.Image = pic;
                        //actalizamos la dv
                        db.Entry(product).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(CombosHelpers.GetCategories(user.CompanyId), "CategoryId", "Description", product.CategoryId);
            ViewBag.TaxId      = new SelectList(CombosHelpers.GetTaxes(user.CompanyId), "TaxId", "Description", product.TaxId);
            return(View(product));
        }
Example #3
0
        public async Task <IActionResult> DownloadAsync(string feature, string preferId, string fileName)
        {
            try
            {
                var rootFolder  = Utils.getRootFolder();
                var imageFolder = rootFolder + Utils.uploadFolder();
                var filePath    = imageFolder + @"/" + feature + @"/" + preferId + @"/" + fileName;

                if (filePath == null)
                {
                    return(Content("filename not present"));
                }
                var memory = new MemoryStream();
                using (FileStream stream = new FileStream(filePath, FileMode.Open))
                {
                    await stream.CopyToAsync(memory);
                }
                memory.Position = 0;
                return(File(memory, FilesHelpers.GetContentType(filePath), Path.GetFileName(filePath)));
            }
            catch (Exception ex)
            {
                return(NotFound(ex.Message));
            }
        }
Example #4
0
        public async Task <ActionMessage> Create(AcceptanceInfo obj, [FromForm] List <IFormFile> files, string _userI)
        {
            ActionMessage        ret           = new ActionMessage();
            int                  insetId       = -1;
            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    insetId = AcceptanceDataLayer.GetInstance().Create(connection, obj, _userI);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            if (insetId > -1)
            {
                ret.id = insetId;
                using (SqlConnection connection = sqlConnection.GetConnection())
                {
                    try
                    {
                        foreach (DeliveryReceiptItemInfoNew item in obj.Items)
                        {
                            ProposalDataLayer.GetInstance().UpdateItemAcceptance(connection, item, _userI);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                if (files != null)
                {
                    foreach (var item in files)
                    {
                        DocumentInfo documentInfo = new DocumentInfo();
                        documentInfo.TableName = TableFile.Acceptance.ToString();
                        documentInfo.PreferId  = insetId.ToString();
                        documentInfo.Link      = DateTime.Now.ToString("yyMMddHHmmssfff") + "-" + Utils.ChuyenTVKhongDau(item.FileName);
                        documentInfo.FileName  = item.FileName;
                        documentInfo.Length    = item.Length.ToString();
                        documentInfo.Type      = item.ContentType;
                        ret = await FilesHelpers.UploadFile(TableFile.Acceptance.ToString(), insetId.ToString(), item, documentInfo.Link);

                        DocumentService.GetInstance().InsertDocument(documentInfo, _userI.ToString());
                    }
                }
                ret.isSuccess = true;
            }
            else
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "lỗi thêm phiếu nghiệm thu";
                ret.err.msgString = "lỗi thêm phiếu nghiệm thu";
            }
            return(ret);
        }
Example #5
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();

                UsersHelper.CreateUserASP(user.UserName, "User");

                if (user.PhotoFile != null)
                {
                    var folder  = "~/Content/Users";
                    var file    = string.Format("{0}-{1}.jpg", user.UserId, user.FullName);
                    var respose = FilesHelpers.UploadPhoto(user.PhotoFile, folder, file);

                    if (respose)
                    {
                        var pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        user.Photo = pic;
                        //actalizamos la dv
                        db.Entry(user).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
Example #6
0
        public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();

                if (company.LogoFile != null)
                {
                    var folder  = "~/Content/Logos";
                    var file    = string.Format("{0}-{1}.jpg", company.CompanyId, company.Name);
                    var respose = FilesHelpers.UploadPhoto(company.LogoFile, folder, file);

                    if (respose)
                    {
                        var pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        company.Logo = pic;
                        //actalizamos la dv
                        db.Entry(company).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", company.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", company.DepartmentId);
            return(View(company));
        }
Example #7
0
        public ActionResult Edit(Product product)
        {
            if (ModelState.IsValid)
            {
                if (product.ImageFile != null)
                {
                    var pic = string.Empty;

                    var folder  = "~/Content/Products";
                    var file    = string.Format("{0}-{1}.jpg", product.ProductId, product.Description);
                    var respose = FilesHelpers.UploadPhoto(product.ImageFile, folder, file);

                    if (respose)
                    {
                        pic           = string.Format("{0}/{1}", folder, file);
                        product.Image = pic;
                    }
                }

                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(CombosHelpers.GetCategories(product.CompanyId), "CategoryId", "Description", product.CategoryId);
            ViewBag.TaxId      = new SelectList(CombosHelpers.GetTaxes(product.CompanyId), "TaxId", "Description", product.TaxId);

            return(View(product));
        }
Example #8
0
        public async Task <ActionResult> Edit(ProductView view)
        {
            if (ModelState.IsValid)
            {
                var picture = view.ImagePath;
                var folder  = "~/Content/Products";
                if (view.ImageFile != null)
                {
                    picture = FilesHelpers.UploadPhoto(view.ImageFile, folder);
                    picture = $"{folder}/{picture}";
                }

                var product = this.ToProduct(view, picture);
                try
                {
                    db.Entry(product).State = EntityState.Modified;

                    await db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                }

                return(RedirectToAction("Index"));
            }
            return(View(view));
        }
Example #9
0
        public async Task <ActionMessage> Put(int id, [FromForm] NegotiationInfo _Negotiation, [FromForm] List <IFormFile> files, string _userID)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = NegotiationService.GetInstance().editNegotiation(id, _Negotiation, GetUserId(), _userID);
                //update list file

                DocumentService.GetInstance().DeleteDocumentsNotExitsInList(_Negotiation.ListDocument, TableFile.Negotiation.ToString(), id);
                foreach (var item in files)
                {
                    DocumentInfo documentInfo = new DocumentInfo();
                    documentInfo.TableName = TableFile.Negotiation.ToString();
                    documentInfo.PreferId  = id.ToString();
                    documentInfo.FileName  = item.FileName;
                    documentInfo.Link      = DateTime.Now.ToString("yyMMddHHmmssfff") + "-" + Utils.ChuyenTVKhongDau(item.FileName);
                    documentInfo.Length    = item.Length.ToString();
                    documentInfo.Type      = item.ContentType;
                    ret = await FilesHelpers.UploadFile(TableFile.Negotiation.ToString(), _Negotiation.NegotiationID.ToString(), item, documentInfo.Link);

                    DocumentService.GetInstance().InsertDocument(documentInfo, GetUserId());
                }
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
Example #10
0
        public async Task <ActionMessage> PostwithAttFile([FromForm] NegotiationInfo NegotiationObj, [FromForm] List <IFormFile> files)
        {
            ActionMessage ret     = new ActionMessage();
            int           insetId = -1;

            try
            {
                insetId       = NegotiationService.GetInstance().createNegotiation2(NegotiationObj, GetUserId());
                ret.isSuccess = true;
                if (insetId > -1)
                {
                    ret.id = insetId;
                    foreach (var item in files)
                    {
                        DocumentInfo documentInfo = new DocumentInfo();
                        documentInfo.TableName = TableFile.Negotiation.ToString();
                        documentInfo.PreferId  = insetId.ToString();
                        documentInfo.Link      = DateTime.Now.ToString("yyMMddHHmmssfff") + "-" + Utils.ChuyenTVKhongDau(item.FileName);
                        documentInfo.FileName  = item.FileName;
                        documentInfo.Length    = item.Length.ToString();
                        documentInfo.Type      = item.ContentType;
                        ret = await FilesHelpers.UploadFile(TableFile.Negotiation.ToString(), insetId.ToString(), item, documentInfo.Link);

                        DocumentService.GetInstance().InsertDocument(documentInfo, GetUserId());
                    }
                }
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
Example #11
0
        public async Task <ActionMessage> EditExplanation(int id, ExplanationInfo _Explanation, string _userU, [FromForm] List <IFormFile> files)
        {
            ActionMessage        ret           = new ActionMessage();
            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();



            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    UserLogInfo info = new UserLogInfo();
                    info.Action      = "Edit";
                    info.Description = "ngày : " + _Explanation.InTime + " code : " + _Explanation.ExplanationCode
                                       + " trạng thái : " + _Explanation.Status;
                    info.Feature  = TableFile.Proposal.ToString();
                    info.Time     = DateTime.Now;
                    info.UserName = _userU;
                    info.UserID   = 1;
                    UserService.GetInstance().TrackUserAction(info);
                    ExplanationDataLayer.GetInstance().UpdateExplanation(connection, id, _Explanation, _userU);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            DocumentService.GetInstance().DeleteDocumentsNotExitsInList(_Explanation.ListDocument, TableFile.Explanation.ToString(), id);

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    foreach (ItemPropsalInfo item in _Explanation.Items)
                    {
                        ProposalDataLayer.GetInstance().UpdateItemExplanation(connection, item, _userU);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            foreach (var item in files)
            {
                DocumentInfo documentInfo = new DocumentInfo();
                documentInfo.TableName = TableFile.Explanation.ToString();
                documentInfo.PreferId  = id.ToString();
                documentInfo.Link      = DateTime.Now.ToString("yyMMddHHmmssfff") + "-" + Utils.ChuyenTVKhongDau(item.FileName);
                documentInfo.FileName  = item.FileName;
                documentInfo.Length    = item.Length.ToString();
                documentInfo.Type      = item.ContentType;
                ret = await FilesHelpers.UploadFile(TableFile.Explanation.ToString(), id.ToString(), item, documentInfo.Link);

                DocumentService.GetInstance().InsertDocument(documentInfo, _userU.ToString());
            }
            ret.isSuccess = true;
            return(ret);
        }
Example #12
0
        public ActionMessage DeleteDocuments(string ids)
        {
            ActionMessage ret = new ActionMessage();

            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    List <DocumentInfo> infos = DocumentDataLayer.GetInstance().GetDocumentsByIds(connection, ids);
                    if (infos.Count > 0)
                    {
                        foreach (DocumentInfo document in infos)
                        {
                            FilesHelpers.DeleteFile(document.TableName, document.PreferId, document.FileName);
                        }
                    }
                    DocumentDataLayer.GetInstance().DeleteDocuments(connection, ids);
                    ret.isSuccess = true;
                }
                catch (Exception ex)
                {
                    ret.isSuccess     = false;
                    ret.err.msgCode   = "Internal Error";
                    ret.err.msgString = ex.Message;
                }
            }
            return(ret);
        }
Example #13
0
        public ActionMessage DeleteDocument(int id)
        {
            ActionMessage ret = new ActionMessage();

            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    DocumentInfo info = DocumentDataLayer.GetInstance().GetDocumentById(connection, id);
                    if (info.PreferId != null && info.TableName != "")
                    {
                        FilesHelpers.DeleteFile(info.TableName, info.PreferId, info.FileName);
                    }
                    DocumentDataLayer.GetInstance().DeleteDocument(connection, id);
                    ret.isSuccess = true;
                }
                catch (Exception ex)
                {
                    ret.isSuccess     = false;
                    ret.err.msgCode   = "Internal Error";
                    ret.err.msgString = ex.ToString();
                }
            }
            return(ret);
        }
Example #14
0
        public ActionMessage DeleteDocumentsByFeature(string feature, string ids)
        {
            ActionMessage ret = new ActionMessage();

            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    string[] IDsarray = ids.Split(',');
                    foreach (string id in IDsarray)
                    {
                        FilesHelpers.DeleteFolder(feature, id);
                        DocumentDataLayer.GetInstance().DeleteDocumentByFeatureAndID(connection, feature, Int32.Parse(id));
                    }
                    ret.isSuccess = true;
                }
                catch (Exception ex)
                {
                    ret.isSuccess     = false;
                    ret.err.msgCode   = "Internal Error";
                    ret.err.msgString = ex.ToString();
                }
            }
            return(ret);
        }
Example #15
0
        public async Task <Data.Models.FileInfo> MoveTempFile(string tempFileName, string relativeFolderPath, string fileName)
        {
            var(fileNameWithoutExt, extension) = FilesHelpers.GetFileNameAndExtension(fileName);
            var fileInfo = await fileProvider.MoveTempFile(tempFileName, relativeFolderPath, fileNameWithoutExt, extension);

            var file = await CreateFileInfoToDb(relativeFolderPath, fileNameWithoutExt, extension);

            return(file);
        }
Example #16
0
        public async Task <ActionMessage> editBidPlan(int id, BidPlanInfo _BidPlan, string _userU, IList <IFormFile> files, string _userID)
        {
            ActionMessage        ret           = new ActionMessage();
            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                var chkBidPlanInfo = BidPlanDataLayer.GetInstance().getBidPlan(connection, id, _userID);
                if (chkBidPlanInfo != null)
                {
                    try
                    {
                        QuoteInfo quoteInfo = QuoteDataLayer.GetInstance().getQuote(connection, _BidPlan.QuoteID, _userID);
                        if (quoteInfo != null)
                        {
                            _BidPlan.QuoteID = quoteInfo.QuoteID;

                            //var ProposalInfo = ProposalDataLayer.GetInstance().getProposalDetail(connection, _BidPlan.ProposalID);
                            //if (ProposalInfo != null)
                            //{
                            //    _BidPlan.ProposalCode = ProposalInfo.ProposalCode;
                            //}
                        }
                        else
                        {
                            _BidPlan.QuoteID /*= _BidPlan.ProposalID*/ = 0;
                        }
                        BidPlanDataLayer.GetInstance().UpdateBidPlan(connection, id, _BidPlan, _userU);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                DocumentService.GetInstance().DeleteDocumentsNotExitsInList(_BidPlan.ListDocument, TableFile.BidPlan.ToString(), _BidPlan.BidPlanID);

                foreach (var item in files)
                {
                    DocumentInfo documentInfo = new DocumentInfo();
                    documentInfo.TableName = TableFile.BidPlan.ToString();
                    documentInfo.PreferId  = _BidPlan.BidPlanID.ToString();
                    documentInfo.Link      = DateTime.Now.ToString("yyMMddHHmmssfff") + "-" + Utils.ChuyenTVKhongDau(item.FileName);
                    documentInfo.FileName  = item.FileName;
                    documentInfo.Length    = item.Length.ToString();
                    documentInfo.Type      = item.ContentType;
                    ret = await FilesHelpers.UploadFile(TableFile.BidPlan.ToString(), _BidPlan.BidPlanID.ToString(), item, documentInfo.Link);

                    DocumentService.GetInstance().InsertDocument(documentInfo, _userU);
                }
                ret.isSuccess = true;


                return(ret);
            }
        }
Example #17
0
        public async Task <ActionMessage> Update(AcceptanceInfo obj, [FromForm] List <IFormFile> files, string _userI)
        {
            ActionMessage ret = new ActionMessage();

            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    AcceptanceDataLayer.GetInstance().Update(connection, obj, _userI);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            DocumentService.GetInstance().DeleteDocumentsNotExitsInList(obj.ListDocument, TableFile.Acceptance.ToString(), obj.AcceptanceID);

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    foreach (DeliveryReceiptItemInfoNew item in obj.Items)
                    {
                        ProposalDataLayer.GetInstance().UpdateItemAcceptance(connection, item, _userI);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            if (files != null)
            {
                foreach (var item in files)
                {
                    DocumentInfo documentInfo = new DocumentInfo();
                    documentInfo.TableName = TableFile.Acceptance.ToString();
                    documentInfo.PreferId  = obj.AcceptanceID.ToString();
                    documentInfo.Link      = DateTime.Now.ToString("yyMMddHHmmssfff") + "-" + Utils.ChuyenTVKhongDau(item.FileName);
                    documentInfo.FileName  = item.FileName;
                    documentInfo.Length    = item.Length.ToString();
                    documentInfo.Type      = item.ContentType;
                    ret = await FilesHelpers.UploadFile(TableFile.Acceptance.ToString(), obj.AcceptanceID.ToString(), item, documentInfo.Link);

                    DocumentService.GetInstance().InsertDocument(documentInfo, _userI.ToString());
                }
            }
            ret.isSuccess = true;


            return(ret);
        }
Example #18
0
        public async Task <ActionMessage> createBidPlan2(BidPlanInfo _BidPlan, string _userI, IList <IFormFile> files, string _userID)
        {
            ActionMessage        ret           = new ActionMessage();
            int                  insetId       = -1;
            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    QuoteInfo quoteInfo = QuoteDataLayer.GetInstance().getQuote(connection, _BidPlan.QuoteID, _userID);
                    if (quoteInfo != null)
                    {
                        _BidPlan.QuoteID = quoteInfo.QuoteID;
                    }
                    else
                    {
                        _BidPlan.QuoteID /*= _BidPlan.ProposalID*/ = 0;
                    }
                    insetId = BidPlanDataLayer.GetInstance().InsertBidPlan(connection, _BidPlan, _userI);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                if (insetId > -1)
                {
                    ret.id = insetId;
                    foreach (var item in files)
                    {
                        DocumentInfo documentInfo = new DocumentInfo();
                        documentInfo.TableName = TableFile.BidPlan.ToString();
                        documentInfo.PreferId  = insetId.ToString();
                        documentInfo.Link      = DateTime.Now.ToString("yyMMddHHmmssfff") + "-" + Utils.ChuyenTVKhongDau(item.FileName);
                        documentInfo.FileName  = item.FileName;
                        documentInfo.Length    = item.Length.ToString();
                        documentInfo.Type      = item.ContentType;
                        ret = await FilesHelpers.UploadFile(TableFile.BidPlan.ToString(), insetId.ToString(), item, documentInfo.Link);

                        DocumentService.GetInstance().InsertDocument(documentInfo, _userI.ToString());
                    }
                    ret.isSuccess = true;
                }
                else
                {
                    ret.isSuccess     = false;
                    ret.err.msgCode   = "lỗi thêm biên bản họp giá";
                    ret.err.msgString = "lỗi thêm biên bản họp giá";
                }
                return(ret);
            }
        }
Example #19
0
        public async Task <IActionResult> PostSubmitTask(CreateTaskSubmissionRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var studentTask = await _context.StudentAssignedTasks
                              .FirstOrDefaultAsync(st => st.Id == request.StudentTaskId);

            if (studentTask is null)
            {
                return(NotFound());
            }

            if (studentTask.StudentId != userManager.GetUserId(User))
            {
                return(Forbid());
            }

            var submission = new TaskSubmission {
                AssignedTaskId = studentTask.Id,
                State          = TaskSubmissionState.Submitted,
                DateAdded      = DateTime.Now,
                Files          = new List <TaskSubmissionFile>(),
                Description    = request.Description
            };

            _context.TaskSubmissions.Add(submission);
            await _context.SaveChangesAsync();

            foreach (var uploadedFile in request.UploadedFiles)
            {
                var submissionFolder = $"StudentSubmissions/{studentTask.StudentId}/{studentTask.Id}/{submission.Id}";

                // TODO: validate file extension.
                var(fileName, extension) = FilesHelpers.GetFileNameAndExtension(uploadedFile.OriginalName);

                var file = await fileService.MoveTempFile(uploadedFile.TempFileName, submissionFolder, uploadedFile.OriginalName);

                submission.Files.Add(new TaskSubmissionFile {
                    FileId         = file.Id,
                    FileType       = TaskSubmissionFileType.SourceCode,
                    TaskSubmission = submission
                });
            }

            await _context.SaveChangesAsync();

            return(Ok());
        }
Example #20
0
        public async Task <ActionMessage> Put(int id, [FromForm] ProposalInfo _proposal, [FromForm] List <IFormFile> files)
        {
            ActionMessage ret = new ActionMessage();

            ret.isSuccess = true;
            try
            {
                ret = ProposalService.GetInstance().editProposal(id, _proposal, GetUserId());
                //update list file
                //ProposalService.GetInstance().DelteDocument(id.ToString());
                if (ret.isSuccess == false)
                {
                    return(ret);
                }
                //++edit item
                ret = ProposalService.GetInstance().EditItems(id, _proposal.Items);
                if (ret.isSuccess == false)
                {
                    return(ret);
                }


                //++EDIT document
                //delete old document
                DocumentService.GetInstance().DeleteDocumentsNotExitsInList(_proposal.Documents, TableFile.Proposal.ToString(), id);
                //add new document
                foreach (var item in files)
                {
                    DocumentInfo documentInfo = new DocumentInfo();
                    documentInfo.TableName = TableFile.Proposal.ToString();
                    documentInfo.PreferId  = id.ToString();
                    documentInfo.FileName  = item.FileName;
                    documentInfo.Link      = DateTime.Now.ToString("yyMMddHHmmssfff") + "-" + Utils.ChuyenTVKhongDau(item.FileName);
                    documentInfo.Length    = item.Length.ToString();
                    documentInfo.Type      = item.ContentType;
                    ret = await FilesHelpers.UploadFile(TableFile.Proposal.ToString(), _proposal.ProposalID.ToString(), item, documentInfo.Link);

                    DocumentService.GetInstance().InsertDocument(documentInfo, GetUserId());
                }
                //--EDIT document
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
Example #21
0
        public async Task <ActionMessage> PostwithAttFile([FromForm] ProposalInfo propsalObj, [FromForm] List <IFormFile> files)
        {
            ActionMessage ret     = new ActionMessage();
            int           insetId = -1;

            try
            {
                ret.isSuccess = true;
                insetId       = ProposalService.GetInstance().createProposal2(propsalObj, GetUserId());
                if (insetId > -1)
                {
                    // upload file
                    //ret = await FilesHelpers.UploadFiles("proposal", insetId.ToString(), files);
                    // update list file
                    ret = ProposalService.GetInstance().insertItems(insetId, propsalObj.Items, propsalObj.DateIn, propsalObj.DepartmentID);
                    if (ret.isSuccess == false)
                    {
                        return(ret);
                    }
                    foreach (var item in files)
                    {
                        DocumentInfo documentInfo = new DocumentInfo();
                        documentInfo.TableName = TableFile.Proposal.ToString();
                        documentInfo.PreferId  = insetId.ToString();
                        documentInfo.Link      = DateTime.Now.ToString("yyMMddHHmmssfff") + "-" + Utils.ChuyenTVKhongDau(item.FileName);
                        documentInfo.FileName  = item.FileName;
                        documentInfo.Length    = item.Length.ToString();
                        documentInfo.Type      = item.ContentType;
                        ret = await FilesHelpers.UploadFile(TableFile.Proposal.ToString(), insetId.ToString(), item, documentInfo.Link);

                        DocumentService.GetInstance().InsertDocument(documentInfo, GetUserId());
                    }
                }
                else
                {
                    ret.isSuccess     = false;
                    ret.err.msgCode   = "lỗi thêm proposal";
                    ret.err.msgString = "lỗi thêm proposal";
                }
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
Example #22
0
        public ActionResult Create(CategoriaVista categoriavista)
        {
            try
            {
                var pic    = string.Empty;
                var folder = "~/Content/ImagenesCategorias";

                if (categoriavista.fotoFile != null)
                {
                    pic = FilesHelpers.UploadPhoto(categoriavista.fotoFile, folder);
                    pic = $"{folder}/{pic}";
                }
                //almaceno los datos en la variable local
                var categoria = this.ToCategoria(categoriavista, pic);

                // comienza la conexión
                MongoClientSettings settings = MongoClientSettings.FromUrl(
                    new MongoUrl(connectionString)
                    );
                settings.SslSettings =
                    new SslSettings()
                {
                    EnabledSslProtocols = SslProtocols.Tls12
                };
                var mongoClient = new MongoClient(settings);
                //var client = new MongoClient(conec);
                var db = mongoClient.GetDatabase(bdname);
                var collectionSettings = new MongoCollectionSettings {
                    ReadPreference = ReadPreference.Nearest
                };



                // var cliente = new MongoClient(conec);

                //var database = cliente.GetDatabase(bdname);
                var listacategorias = db.GetCollection <Categoria>("Categoria");
                //termina la conexión

                listacategorias.InsertOneAsync(categoria);
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #23
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                if (user.PhotoFile != null)
                {
                    var pic = string.Empty;

                    var folder  = "~/Content/Users";
                    var file    = string.Format("{0}-{1}.jpg", user.UserId, user.FullName);
                    var respose = FilesHelpers.UploadPhoto(user.PhotoFile, folder, file);

                    if (respose)
                    {
                        pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        user.Photo = pic;
                    }
                }


                var db2         = new ECommerceContext();
                var currentUser = db2.Users.Find(user.UserId);
                if (currentUser.UserName != user.UserName)
                {
                    UsersHelper.UpdateUserName(currentUser.UserName, user.UserName);
                }
                db2.Dispose();

                //actalizamos la dv
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
Example #24
0
        public ActionResult Create(EntidadVista entidadvista)
        {
            try
            {
                var pic    = string.Empty;
                var folder = "~/Content/ImagenesEntidades";

                if (entidadvista.fotoFile != null)
                {
                    pic = FilesHelpers.UploadPhoto(entidadvista.fotoFile, folder);
                    pic = $"{folder}/{pic}";
                }
                //almaceno los datos en la variable local
                var entidad = this.ToEntidad(entidadvista, pic);


                string connectionString =
                    @"mongodb://*****:*****@appturismo.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&maxIdleTimeMS=120000&appName=@appturismo@";
                MongoClientSettings settings = MongoClientSettings.FromUrl(
                    new MongoUrl(connectionString)
                    );
                settings.SslSettings =
                    new SslSettings()
                {
                    EnabledSslProtocols = SslProtocols.Tls12
                };
                var mongoClient = new MongoClient(settings);
                // var cliente = new MongoClient(conec);
                //bd = cliente.GetDatabase(bdname);
                var database = mongoClient.GetDatabase(bdname);

                var entidades = database.GetCollection <Entidad>("Entidad");
                entidades.InsertOneAsync(entidad);
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #25
0
        public async Task <ActionResult> Edit(CategoryView view)
        {
            if (ModelState.IsValid)
            {
                var pic    = view.ImagePath;
                var folder = "~/Content/Categories";

                if (view.ImageFile != null)
                {
                    pic = FilesHelpers.UploadPhoto(view.ImageFile, folder);
                    pic = $"{folder}/{pic}";
                }

                var category = this.ToCategory(view, pic);
                this.db.Entry(category).State = EntityState.Modified;
                await this.db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(view));
        }
Example #26
0
        public async Task <ActionResult> Create(CategoryView view)
        {
            if (ModelState.IsValid)
            {
                var pic    = string.Empty;
                var folder = "~/Content/Categories";

                if (view.ImageFile != null)
                {
                    pic = FilesHelpers.UploadPhoto(view.ImageFile, folder);
                    pic = $"{folder}/{pic}";
                }

                var category = this.ToCategory(view, pic);
                this.db.Categories.Add(category);
                await this.db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(view));
        }
Example #27
0
        public async Task <Data.Models.FileInfo> MoveFile(Guid sourceFileId, string relativeFolderPath, string fileName)
        {
            var(fileNameWithoutExtension, extension) = FilesHelpers.GetFileNameAndExtension(fileName);

            var file = await context.Files.FindAsync(sourceFileId);

            if (file is null)
            {
                throw new InvalidOperationException("No file with the provided sourceFileId exists.");
            }

            var sourceFileInfo = await fileProvider.GetFile(file.RelativeFolderPath, file.FileName, file.Extension);

            var fileInfo = await fileProvider.MoveFile(sourceFileInfo, relativeFolderPath, fileNameWithoutExtension, extension);

            file.RelativeFolderPath = relativeFolderPath;
            file.FileName           = fileNameWithoutExtension;
            file.Extension          = extension;
            await context.SaveChangesAsync();

            return(file);
        }
Example #28
0
        public async Task <ActionMessage> AddComment([FromForm] string preferId, [FromForm] string comment, [FromForm] string feature, [FromForm] List <IFormFile> files)
        {
            int           insetId = -1;
            ActionMessage ret     = new ActionMessage();

            try
            {
                CommentInfo commentInfo = new CommentInfo();
                commentInfo.TableName = feature;
                commentInfo.PreferId  = preferId;
                commentInfo.Comment   = comment;
                insetId       = CommentService.GetInstance().InsertComment(commentInfo, GetUserId());
                ret.isSuccess = true;
                if (insetId > -1)
                {
                    foreach (var file in files)
                    {
                        DocumentInfo documentInfo = new DocumentInfo();
                        documentInfo.TableName = TableFile.Comment.ToString();
                        documentInfo.PreferId  = insetId.ToString();
                        documentInfo.Link      = DateTime.Now.ToString("yyMMddHHmmssfff") + "-" + Utils.ChuyenTVKhongDau(file.FileName);
                        documentInfo.FileName  = file.FileName;
                        documentInfo.Length    = file.Length.ToString();
                        documentInfo.Type      = file.ContentType;
                        ret = await FilesHelpers.UploadFile(documentInfo.TableName, insetId.ToString(), file, documentInfo.Link);

                        DocumentService.GetInstance().InsertDocument(documentInfo, GetUserId());
                    }
                }
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Lỗi thêm comment";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
Example #29
0
        public ActionMessage DeleteDocumentByFeature(string feature, int id)
        {
            ActionMessage ret = new ActionMessage();

            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    FilesHelpers.DeleteFolder(feature, id.ToString());
                    DocumentDataLayer.GetInstance().DeleteDocumentByFeatureAndID(connection, feature, id);
                    ret.isSuccess = true;
                }
                catch (Exception ex)
                {
                    ret.isSuccess     = false;
                    ret.err.msgCode   = "Internal Error";
                    ret.err.msgString = ex.ToString();
                }
            }
            return(ret);
        }
Example #30
0
        public void DeleteDocumentsNotExitsInList(List <DocumentInfo> listDocument, string tableName, int preferId)
        {
            DocumentSeachCriteria _cri = new DocumentSeachCriteria();

            _cri.TableName = tableName;
            _cri.PreferId  = preferId.ToString();
            List <DocumentInfo> currentDocument = GetDocument(_cri);
            List <DocumentInfo> listDelete      = new List <DocumentInfo>();

            if (listDocument == null)
            {
                listDelete = currentDocument;
            }
            else
            {
                listDelete = currentDocument.Where(el2 => !listDocument.Any(el1 => el1.AutoID == el2.AutoID)).ToList();
            }

            //delete data in tables
            if (listDelete.Count > 0)
            {
                string        deleteIds = "";
                List <string> filesName = new List <string>();
                foreach (DocumentInfo document in listDelete)
                {
                    deleteIds += document.AutoID + ",";
                }
                deleteIds = deleteIds.Remove(deleteIds.Length - 1);
                SqlConnectionFactory sqlConnection = new SqlConnectionFactory();
                using (SqlConnection connection = sqlConnection.GetConnection())
                {
                    DocumentDataLayer.GetInstance().DeleteDocuments(connection, deleteIds);
                }
                //delete file physical
                FilesHelpers.DeleteFiles(tableName, preferId.ToString(), filesName);
            }
        }