private void UploadAttachments(DocumentMaster master)
        {
            var httpRequest = HttpContext.Current.Request;

            master.Title       = httpRequest.Params["title"];
            master.Description = httpRequest.Params["description"];
            if (httpRequest.Files.Count > 0)
            {
                foreach (string file in httpRequest.Files)
                {
                    var postedFile = httpRequest.Files[file];
                    if (postedFile != null && postedFile.ContentLength > 0)
                    {
                        string serverAddress = Process(postedFile);
                        switch (file)
                        {
                        case "Documents":
                            if (master.Documents != null)
                            {
                                master.Documents += ";" + serverAddress;
                            }
                            else
                            {
                                master.Documents = serverAddress;
                            }
                            break;
                        }
                    }
                }
            }
        }
Пример #2
0
        public async Task <int> AddMasterDocument(DocumentMaster documentmaster)
        {
            db.DocumentMaster.Add(documentmaster);
            int result = await db.SaveChangesAsync();

            return(result);
        }
Пример #3
0
        public DocumentMaster AddDocumentType(DocumentEL document)
        {
            DocumentMaster newDoc = new DocumentMaster();

            using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadCommitted
            }))
            {
                try
                {
                    if (document != null)
                    {
                        using (uow = new UnitOfWork.UnitOfWork())
                        {
                            #region Add New Document
                            newDoc.Description  = document.Description;
                            newDoc.DocumentName = document.DocumentTypeName;
                            uow.DocumentMasterRepository.Insert(newDoc);
                            uow.Save();
                            #endregion
                            transactionScope.Complete();
                        }
                    }
                }
                catch (Exception ex)
                {
                    transactionScope.Dispose();
                }
                return(newDoc);
            }
        }
Пример #4
0
        public void Create(DocumentDTO documentDTO)
        {
            DocumentMaster obj = _mapper.Map <DocumentMaster>(documentDTO);

            obj.CreatedDate = DateTime.Now;
            _unitOfWork.DocumentMaster.Create(obj);
            _unitOfWork.SaveChanges();
        }
Пример #5
0
        public async Task <int> DeleteMasterDocument(int id)
        {
            DocumentMaster document = await GetMasterDocumentByID(id);

            db.DocumentMaster.Remove(document);
            int result = await db.SaveChangesAsync();

            return(result);
        }
Пример #6
0
        public async Task <int> UpdateMasterDocument(DocumentMaster documentmaster)
        {
            DocumentMaster document = await GetMasterDocumentByID(documentmaster.DocumentMasterId);

            db.Entry(document).State = EntityState.Detached;
            db.Entry(document).State = EntityState.Modified;
            int result = await db.SaveChangesAsync();

            return(result);
        }
Пример #7
0
 public byte PriceTypeByDocumentType(DocumentMaster DocumentType)
 {
     if (DocumentType.Id == 1 || DocumentType.Id == 2)
     {
         return(2);
     }
     if (DocumentType.Id == 3 || DocumentType.Id == 4)
     {
         return(1);
     }
     return(0);
 }
Пример #8
0
        public bool EditDocumentType(DocumentEL document)
        {
            bool isUpdated = false;

            try
            {
                if (document != null)
                {
                    DocumentMaster existingDoc = null;

                    using (uow = new UnitOfWork.UnitOfWork())
                    {
                        existingDoc = uow.DocumentMasterRepository.Get().Where(u => u.DocumentID.Equals(document.DocumentTypeID)).FirstOrDefault();

                        #region Get Existing User

                        if (existingDoc == null)
                        {
                            return(isUpdated);
                        }
                        // Check updating email id exists for other user

                        #endregion


                        #region Update Document

                        existingDoc.DocumentName = document.DocumentTypeName;
                        existingDoc.Description  = document.Description;

                        uow.DocumentMasterRepository.Update(existingDoc);
                        uow.Save();

                        #endregion

                        #region PrepareResponse

                        isUpdated = true;

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                isUpdated = false;
                return(isUpdated);
            }

            return(isUpdated);
        }
Пример #9
0
 private void MapDocuments(DocumentMaster master, DocumentMasterDto dto)
 {
     dto.CreatedTime = master.CreatedTime;
     dto.DeletedTime = master.DeletedTime;
     dto.Description = master.Description;
     dto.Id          = master.Id;
     dto.IsDeleted   = master.IsDeleted;
     dto.Title       = master.Title;
     dto.Download    = master.Download ?? 0;
     if (master.Documents != null)
     {
         var documents = master.Documents.Split(new char[] { ';' });
         dto.Documents = documents.ToList();
     }
 }
Пример #10
0
        public bool DeleteDocumentType(string id)
        {
            bool isDeleted = false;

            try
            {
                using (uow = new UnitOfWork.UnitOfWork())
                {
                    DocumentMaster doc = uow.DocumentMasterRepository.Get().Where(x => x.DocumentID == Convert.ToInt32(id)).FirstOrDefault();
                    uow.DocumentMasterRepository.Delete(doc);
                    uow.Save();
                }
            }
            catch (Exception ex)
            {
            }
            return(isDeleted);
        }
 public IHttpActionResult PutDocuments(DocumentMaster master)
 {
     try
     {
         using (MususAppEntities entity = new MususAppEntities())
         {
             var app = entity.DocumentMasters.FirstOrDefault(x => x.Id == master.Id);
             app.Description = master.Description;
             app.Documents   = master.Documents;
             app.Title       = master.Title;
             entity.SaveChanges();
             return(Ok("web page app changed successfully"));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
        public IHttpActionResult PostDocuments()
        {
            try
            {
                using (MususAppEntities entity = new MususAppEntities())
                {
                    var            httpRequest = HttpContext.Current.Request;
                    DocumentMaster master      = null;
                    if (httpRequest.Params["id"] != null)
                    {
                        var id = Guid.Parse(httpRequest.Params["id"]);
                        master = entity.DocumentMasters.FirstOrDefault(
                            x => x.Id == id);
                        if (master != null)
                        {
                            UploadAttachments(master);
                        }
                        else
                        {
                            BadRequest("Document not found");
                        }
                    }

                    else
                    {
                        master             = new DocumentMaster();
                        master.Id          = Guid.NewGuid();
                        master.DeletedTime = null;
                        master.IsDeleted   = false;
                        master.CreatedTime = DateTime.UtcNow;
                        UploadAttachments(master);
                        entity.DocumentMasters.Add(master);
                    }

                    entity.SaveChanges();
                    return(Ok(master));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #13
0
        public decimal CalculateLinePrice(ItemView item, DocumentMaster documentType, List <ItemPrice> itemPrices)
        {
            byte priceType = PriceTypeByDocumentType(documentType);

            decimal price = 0;

            ItemPrice priceOfCard = itemPrices.Where(x => x.ItemId == item.Id && x.PriceTypeId == priceType).FirstOrDefault();

            if (priceOfCard != null)
            {
                price = priceOfCard.Price;
            }
            else
            {
                price = GetItemDefaultPriceByDocumentType(item, documentType);
            }
            return(price);

            //if (priceType == 2) return item.DefaultSalePrice;
            //if (priceType == 1) return item.DefaultPurchasePrice;

            //decimal itemPrice = 0;
            //byte priceType = 0;
            //if (DocumentType.Id == 1 || DocumentType.Id == 2)
            //{
            //    itemPrice = item.DefaultSalePrice;
            //    priceType = 2;
            //}
            //else
            //{
            //    itemPrice = item.DefaultPurchasePrice;
            //    priceType = 1;
            //}

            //decimal linePrice = itemPrice;
            //ItemPrice priceOfCard = itemPrices.Where(x => x.ItemId == line.ItemId && x.PriceTypeId == priceType).FirstOrDefault();
            //if (priceOfCard != null) linePrice = priceOfCard.Price;
            //if (isNew && updateLinePrice) line.LinePrice = linePrice;
            //decimal price = 0;
            //if (LineCalType == 1) price = Math.Round(Price * Quantity, 2);
            //if (LineCalType == 2) price = Math.Round(Price * Quantity * Width * Lenght / 1000000, 2);
            //return price;
        }
Пример #14
0
        public DocumentEL GetDocumentTypeByName(string documentname)
        {
            DocumentEL docEl = new DocumentEL();

            try
            {
                using (uow = new UnitOfWork.UnitOfWork())
                {
                    DocumentMaster doc = uow.DocumentMasterRepository.Get().Where(x => x.DocumentName == documentname).FirstOrDefault();
                    docEl.DocumentTypeID   = doc.DocumentID;
                    docEl.DocumentTypeName = doc.DocumentName;
                    docEl.Description      = doc.Description;
                }
            }
            catch (Exception ex)
            {
            }
            return(docEl);
        }
        /// <summary>
        /// Get Record on the basis of recordID from City
        /// </summary>
        /// <param name="recordID"></param>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public DocumentMaster GetDocumentMasterRecord(string recordID, string UserSNo)
        {
            DocumentMaster DocumentMaster = new DocumentMaster();
            SqlDataReader  dr             = null;

            try
            {
                SqlParameter[] Parameters = { new SqlParameter("@SNo", recordID), new SqlParameter("@UserID", Convert.ToInt32(UserSNo)) };
                dr = SqlHelper.ExecuteReader(DMLConnectionString.WebConfigConnectionString, CommandType.StoredProcedure, "GetRecordDocumentMaster", Parameters);
                if (dr.Read())
                {
                    DocumentMaster.SNo = Convert.ToInt32(dr["SNo"]);
                    //city.ZoneSNo = dr["ZoneSNo"].ToString() == "" ? 0 : Convert.ToInt32(dr["ZoneSNo"]);
                    DocumentMaster.DocumentName = dr["DocumentName"].ToString().ToUpper();
                    //city.Text_ZoneSNo = dr["ZoneName"].ToString().ToUpper();
                    DocumentMaster.Description = dr["Description"].ToString().ToUpper();

                    if (!String.IsNullOrEmpty(dr["IsActive"].ToString()))
                    {
                        DocumentMaster.IsActive = Convert.ToBoolean(dr["IsActive"]);
                        DocumentMaster.Active   = dr["Active"].ToString().ToUpper();
                    }


                    DocumentMaster.UpdatedBy = dr["UpdatedUser"].ToString().ToUpper();
                    DocumentMaster.CreatedBy = dr["CreatedUser"].ToString().ToUpper();
                }
                //}
                //catch(Exception ex)// (Exception e)
                //{

                //dr.Close();
                //}
                dr.Close();
                return(DocumentMaster);
            }
            catch (Exception ex)//
            {
                dr.Close();
                throw ex;
            }
        }
Пример #16
0
        public async Task <int> SaveDocument(DocumentMasterDto document)
        {
            DocumentMaster documentMaster = new DocumentMaster();

            try
            {
                // Add document into database
                if (document.DocumentId == 0)
                {
                    documentMaster.Name         = document.Name;
                    documentMaster.DocumentType = (int)document.DocumentType;
                    documentMaster.ClientId     = document.ClientId;
                    documentMaster.CreatedOn    = DateTime.Now;
                    documentMaster.CreatedBy    = Convert.ToInt32(SessionHelper.UserId);
                    documentMaster.Status       = (int)document.Status;
                    documentMaster.FileName     = document.FileName;
                    documentMaster.IsActive     = document.IsActive;
                    _dbContext.DocumentMasters.Add(documentMaster);
                }
                if (document.DocumentId > 0)
                {
                    documentMaster              = _dbContext.DocumentMasters.Where(_ => _.DocumentId == document.DocumentId).FirstOrDefault();
                    documentMaster.Name         = document.Name;
                    documentMaster.DocumentType = (int)document.DocumentType;
                    documentMaster.ClientId     = document.ClientId;
                    documentMaster.ModifiedOn   = DateTime.Now;
                    documentMaster.ModifiedBy   = Convert.ToInt32(SessionHelper.UserId);
                    documentMaster.Status       = (int)document.Status;
                    if (document.FileName != null)
                    {
                        documentMaster.FileName = document.FileName;
                    }
                    documentMaster.IsActive = document.IsActive;
                }
                await _dbContext.SaveChangesAsync();
            }
            catch
            {
            }
            return(documentMaster.DocumentId);
        }
Пример #17
0
        public DocumentMasterDTO SaveDocuments(DocumentMasterDTO _Dto)
        {
            int            entityState     = 0;
            DocumentMaster odocumentmaster = new DocumentMaster();

            if (_Dto.FileData.Length > 0)
            {
                odocumentmaster = db.DocumentMasters.Where(a => a.Id == _Dto.Id).FirstOrDefault();
                if (odocumentmaster != null)
                {
                    entityState = (int)System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    odocumentmaster    = new DocumentMaster();
                    odocumentmaster.Id = Guid.NewGuid();
                    entityState        = (int)System.Data.Entity.EntityState.Added;
                }
                odocumentmaster.FileName    = _Dto.FileName.Replace("-", "").Replace(" ", "");
                odocumentmaster.FileType    = _Dto.FileType;
                odocumentmaster.FileData    = _Dto.FileData;
                odocumentmaster.UserID      = _Dto.UserID;
                odocumentmaster.CreatedDate = System.DateTime.Now;
                if (entityState == (int)System.Data.Entity.EntityState.Added)
                {
                    db.DocumentMasters.Add(odocumentmaster);
                }
                else
                {
                    db.Entry(odocumentmaster).State = System.Data.Entity.EntityState.Modified;
                }
                db.SaveChanges();
                _Dto.Id = odocumentmaster.Id;
            }
            return(_Dto);
        }
Пример #18
0
        /// <summary>
        /// Add and Edit Document Master
        /// </summary>
        /// <param name="data"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public CommonResponse AddAndEditDocumentMaster(DocumentMasterCustom data, long userId = 0)
        {
            CommonResponse obj = new CommonResponse();

            try
            {
                var res = db.DocumentMaster.Where(m => m.DocumentMasterId == data.documentMasterId).FirstOrDefault();
                if (res == null)
                {
                    try
                    {
                        DocumentMaster item = new DocumentMaster();
                        item.Name        = data.name;
                        item.Description = data.description;
                        item.IsActive    = true;
                        item.IsDelete    = false;
                        item.CreatedBy   = userId;
                        item.CreatedOn   = DateTime.Now;
                        item.RecordId    = Guid.NewGuid().ToString();
                        db.DocumentMaster.Add(item);
                        db.SaveChanges();
                        obj.response = ResourceResponse.AddedSucessfully;
                        obj.isStatus = true;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex); if (ex.InnerException != null)
                        {
                            log.Error(ex.InnerException.ToString());
                        }
                        obj.response = ResourceResponse.ExceptionMessage;
                        obj.isStatus = false;
                    }
                }
                else
                {
                    try
                    {
                        res.Name        = data.name;
                        res.Description = data.description;
                        res.ModifiedBy  = userId;
                        res.ModifiedOn  = DateTime.Now;
                        db.SaveChanges();

                        obj.response = ResourceResponse.UpdatedSucessfully;
                        obj.isStatus = true;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex); if (ex.InnerException != null)
                        {
                            log.Error(ex.InnerException.ToString());
                        }
                        obj.response = ResourceResponse.ExceptionMessage;
                        obj.isStatus = false;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex); if (ex.InnerException != null)
                {
                    log.Error(ex.InnerException.ToString());
                }
                obj.response = ResourceResponse.ExceptionMessage;
                obj.isStatus = false;
            }


            return(obj);
        }
Пример #19
0
        public async Task <DocumentMaster> GetMasterDocumentByID(int id)
        {
            DocumentMaster DocumentMaster = await db.DocumentMaster.FindAsync(id);

            return(DocumentMaster);
        }
Пример #20
0
        public async Task <ActionResult> UploadDocument(DocumentMasterDto document, HttpPostedFileBase documentFile)
        {
            try
            {
                #region declaration
                var    documentMaster    = new DocumentMaster();
                var    documentMasterDto = new DocumentMasterDto();
                string folderPath        = Server.MapPath("~/Content/Documents");
                var    directoryDetail   = new DirectoryInfo(folderPath);

                //check directory exist or not && create directory
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }
                #endregion

                if (document != null)
                {
                    if (document.DocumentId == 0 && documentFile != null && documentFile.ContentLength > 0)
                    {
                        document.FileName         = documentFile.FileName;
                        documentMaster.DocumentId = await _documentService.SaveDocument(document);

                        documentFile.SaveAs(folderPath + "/" + documentMaster.DocumentId + "_" + Path.GetFileName(documentFile.FileName));
                        ViewBag.SuccessMsg = "Document Uploaded successfully";
                    }
                    else if (document.DocumentId > 0)
                    {
                        if (documentFile != null && documentFile.ContentLength > 0)
                        {
                            //Save document Detail and file in db
                            document.FileName         = documentFile.FileName;
                            documentMaster.DocumentId = await _documentService.SaveDocument(document);

                            string oldFile = directoryDetail.GetFiles("*" + document.DocumentId + "*.*").FirstOrDefault().Name;

                            if (System.IO.File.Exists(folderPath + "/" + oldFile))
                            {
                                System.IO.File.Delete(folderPath + "/" + oldFile);
                            }
                            documentFile.SaveAs(folderPath + "/" + documentMaster.DocumentId + "_" + documentFile.FileName);
                            ViewBag.SuccessMsg = "Document updated successfully";
                        }
                        else
                        {
                            documentMaster.DocumentId = await _documentService.SaveDocument(document);

                            ViewBag.SuccessMsg = "Document updated successfully";
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                ViewBag.ErrorMsg = "Error occured to upload document";
                throw ex;
            }
            ViewBag.FromDate = Convert.ToDateTime(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 01));
            ViewBag.ToDate   = Convert.ToDateTime(new DateTime(DateTime.Now.Year, DateTime.Now.Month,
                                                               DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)));
            return(View("Index"));
        }