public async Task <BLResponse <bool> > UpdateRoleAsync(AppRoleDTO pDto) { var response = new BLResponse <bool>(); try { var rolModel = Mapper.Map <AppRoleDTO, AppRole>(pDto); var resulAsync = await Uow.Roles.UpdateRoleAsync(rolModel); if (resulAsync.Succeeded) { response.Data = resulAsync.Succeeded; } else { HandleSVCException(ref response, resulAsync.Errors.ToArray()); } } catch (Exception ex) { HandleSVCException(ref response, ex); } return(response); }
public BLResponse<Author> GetAuthors(BLRequest blRequest){ return Client.Execute(proxy=>{ var u= Authors.Get(proxy); var r = new BLResponse<Author>(); if(!IsCayita(blRequest)) r.Result=u; else { HtmlDiv div = new HtmlDiv( ){Name="Author"}; var itag = new HtmlIcon(){ Class="button-add icon-plus-sign", Name="Author" }; div.AddHtmlTag(itag); div.AddHtmlTag(BuildAuthorGrid(u)); HtmlDiv formDiv = new HtmlDiv(){Id="div-form-edit"}; formDiv.Style.Hidden=true; var form = BuildAuthorForm(); form.AddCssClass("span6"); form.Title="Author's Data"; formDiv.AddHtmlTag(form); r.Html= div.ToString()+formDiv.ToString(); } return r; }); }
/// <summary> /// returns all integration summaries /// </summary> /// <returns></returns> public BLResponse <List <IntegrationInfoModel> > GetAllIntegrationInfo() { var blResponse = new BLResponse <List <IntegrationInfoModel> >(); blResponse.ResponseCode = ResponseCode.Success; try { var integrationsQuery = db.Integrations.Select(p => new IntegrationInfoModel { Name = p.Name, Type = p.Type, Status = p.Status, } ); blResponse.ResponseData = integrationsQuery.ToList(); } catch (Exception) { blResponse.ResponseData = null; blResponse.ResponseCode = ResponseCode.Fail; blResponse.ResponseMessage = ResponseMessage.IntegrationNotFound; } return(blResponse); }
public BLResponse<User> SaveUser(SaveUser user, BLRequest blRequest){ Client.Execute(proxy=>{ if(user.Id==default(int)){ Rules.UserRules.ValidateOnSave(user, Users.Count(proxy)); Users.Post(proxy,user); } else{ Rules.UserRules.ValidateOnSave(user); Users.Put(proxy,user); } }); var r = new BLResponse<User>(); if(!IsCayita(blRequest)) r.Result.Add(user); else { var grid = BuildUserGrid(new List<User>()); var dr =grid.CreateRow(user); r.Html= dr.ToString(); } return r; }
public BLResponse<Author> SaveAuthor(SaveAuthor author, BLRequest blRequest){ Client.Execute(proxy=>{ if(author.Id==default(int)){ Rules.AuthorRules.ValidateOnSave(author, Authors.Count(proxy)); Authors.Post(proxy,author); } else{ Rules.AuthorRules.ValidateOnSave(author); Authors.Put(proxy,author); } }); var r = new BLResponse<Author>(); if(!IsCayita(blRequest)) r.Result.Add(author); else { var grid = BuildAuthorGrid(new List<Author>()); var dr =grid.CreateRow(author); r.Html= dr.ToString(); } return r; }
//TODO: response generic error msg on prod mode protected void HandleSVCException(BLResponse pResponse, params string[] pErrors) { string defaultMsg = "Internal Error at Service Layer. "; pResponse.Errors.Add(defaultMsg); pResponse.Errors.AddRange(pErrors); }
/// <summary> /// returns all integration summaries /// </summary> /// <returns></returns> public BLResponse<List<IntegrationInfoModel>> GetAllIntegrationInfo() { var blResponse = new BLResponse<List<IntegrationInfoModel>>(); blResponse.ResponseCode = ResponseCode.Success; try { var integrationsQuery = db.Integrations.Select(p => new IntegrationInfoModel { Name = p.Name, Type = p.Type, Status = p.Status, } ); blResponse.ResponseData = integrationsQuery.ToList(); } catch (Exception) { blResponse.ResponseData = null; blResponse.ResponseCode = ResponseCode.Fail; blResponse.ResponseMessage = ResponseMessage.IntegrationNotFound; } return blResponse; }
public BLResponse<Sale> SendSalesRepo(SendSales request, BLRequest blRequest){ var res = new BLResponse<Sale>(); var mailTarget = request.Email; //MailTarget(blRequest); var sales = GetSalesFromRepo(request, blRequest); var gsbv = (from g in sales group g by g.Vendor into r select new SalesByVendor { Vendor= r.Key, Total= r.Sum(p=>p.Price) }).OrderByDescending(f=>f.Total).ToList(); HtmlDiv div = new HtmlDiv(); var gridSalesByVendor =BuildSalesByVendorGrid(gsbv, mailTarget); div.AddHtmlTag(gridSalesByVendor); div.AddHtmlTag( new HtmlLineBreak()); foreach(var sv in gsbv ){ div.AddHtmlTag(( BuildDetails(sv.Vendor, sales.Where(f=>f.Vendor== sv.Vendor).ToList(), mailTarget))); div.AddHtmlTag( new HtmlLineBreak()); } if(mailTarget.IsNullOrEmpty()){ res.Html= div.ToString(); return res; } SendSalesRepoByMail(div, mailTarget); return res; }
// GET: api/Integrations public IEnumerable <IntegrationInfoModel> GetIntegrations() { BLIntegration blIntegration = new BLIntegration(); BLResponse <List <IntegrationInfoModel> > integrationInfoResponse = blIntegration.GetAllIntegrationInfo(); return(integrationInfoResponse.ResponseData); }
protected void HandleSVCException <T>(ref BLResponse <T> pResponse, Exception pEx) { pResponse.HasErrors = true; pResponse.Errors.Add("Error at Business Service"); pResponse.Errors.Add(pEx.Message); if (pEx.InnerException != null) { pResponse.Errors.Add(pEx.InnerException.Message); } }
public BLResponse<Author> DeleteAuthor(DeleteAuthor author, BLRequest blRequest){ Client.Execute(proxy=>{ Authors.Destroy(proxy, author.Id); }); var r = new BLResponse<Author>(); if(IsCayita(blRequest)) r.Html= "record deleted"; return r; }
public BLResponse<User> DeleteUser(DeleteUser user, BLRequest blRequest){ Client.Execute(proxy=>{ Users.Destroy(proxy, user.Id); }); var r = new BLResponse<User>(); if(IsCayita(blRequest)) r.Html= "record deleted"; return r; }
protected void HandleSVCException(BLResponse pResponse, Exception pEx) { List <string> errs = new List <string>(); do { errs.Add(pEx.Message); pEx = pEx.InnerException; } while (pEx != null); HandleSVCException(pResponse, errs.ToArray()); }
/// <summary> /// returns integration content /// </summary> /// <param name="integrationName"></param> /// <param name="exportType"> category or product</param> /// <returns></returns> public BLResponse <IntegrationModel> GetIntegration(string integrationName, string exportType) { var blResponse = new BLResponse <IntegrationModel>(); blResponse.ResponseCode = ResponseCode.Success; ExportType type = GetExportType(exportType); if (type == ExportType.Undefined) { blResponse.ResponseData = null; blResponse.ResponseCode = ResponseCode.Fail; blResponse.ResponseMessage = ResponseMessage.ExportTypeNotFound; return(blResponse); } try { Api.DAL.DTO.Integration integration = db.Integrations.Single(p => p.Name == integrationName); var integrationDetail = integration.IntegrationDetails.Single(p => p.ExportType == type); var integrationSettings = integration.IntegrationSettings; WebRequest request = WebRequest.Create(integrationDetail.Url); var webResponse = request.GetResponse(); // Get the stream associated with the response. Stream receiveStream = webResponse.GetResponseStream(); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); string webResponseData = readStream.ReadToEnd(); blResponse.ResponseData = new IntegrationModel { Content = GetSerializedData(ref webResponseData, type, integrationSettings) }; webResponse.Close(); readStream.Close(); } catch (Exception) { blResponse.ResponseData = null; blResponse.ResponseCode = ResponseCode.Fail; blResponse.ResponseMessage = ResponseMessage.IntegrationNotFound; } return(blResponse); }
public async Task <BLResponse> CleanTableForInitialUsageAsync() { var response = new BLResponse(); try { await _uow.GetEfRepository <Table>().ExecuteQueryAsync("TRUNCATE TABLE [Resto].[Tables]"); } catch (Exception ex) { HandleSVCException(response, ex); } return(response); }
protected virtual bool StateManagerResponseHandler(BLResponse bLResponse) { if (bLResponse == null) { throw new StateManagerException("Null Result Exception"); } else if (bLResponse.HasError) { throw new StateManagerException(string.Concat(bLResponse.Errors.ToArray())); } else { return(true); } }
/// <summary> /// returns integration content /// </summary> /// <param name="integrationName"></param> /// <param name="exportType"> category or product</param> /// <returns></returns> public BLResponse<IntegrationModel> GetIntegration(string integrationName, string exportType) { var blResponse = new BLResponse<IntegrationModel>(); blResponse.ResponseCode = ResponseCode.Success; ExportType type = GetExportType(exportType); if (type == ExportType.Undefined) { blResponse.ResponseData = null; blResponse.ResponseCode = ResponseCode.Fail; blResponse.ResponseMessage = ResponseMessage.ExportTypeNotFound; return blResponse; } try { Api.DAL.DTO.Integration integration = db.Integrations.Single(p => p.Name == integrationName); var integrationDetail = integration.IntegrationDetails.Single(p => p.ExportType == type); var integrationSettings = integration.IntegrationSettings; WebRequest request = WebRequest.Create(integrationDetail.Url); var webResponse = request.GetResponse(); // Get the stream associated with the response. Stream receiveStream = webResponse.GetResponseStream(); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); string webResponseData = readStream.ReadToEnd(); blResponse.ResponseData = new IntegrationModel { Content = GetSerializedData(ref webResponseData, type, integrationSettings) }; webResponse.Close(); readStream.Close(); } catch (Exception) { blResponse.ResponseData = null; blResponse.ResponseCode = ResponseCode.Fail; blResponse.ResponseMessage = ResponseMessage.IntegrationNotFound; } return blResponse; }
public BLResponse<Sale> GetSales(GetSales request, BLRequest blRequest){ var sales = GetSalesFromRepo(request, blRequest); var r = new BLResponse<Sale>(); if( !IsCayita(blRequest)) { r.Result= sales; } else { r.Html = BuildSalesGrid(sales).ToString(); } return r; }
public async Task <BLResponse <List <AppRoleDTO> > > GetAllRolesAsync() { var response = new BLResponse <List <AppRoleDTO> >(); try { var resulAsync = await Uow.Roles.GeAllRolesAsync(); response.Data = Mapper.Map <List <AppRole>, List <AppRoleDTO> >(resulAsync.ToList()); } catch (Exception ex) { HandleSVCException(ref response, ex); } return(response); }
public async Task <BLResponse <AppRoleDTO> > GetRoleByNameAsync(string pRolName) { var response = new BLResponse <AppRoleDTO>(); try { var resulAsync = await Uow.Roles.GetRoleByNameAsync(pRolName); response.Data = Mapper.Map <AppRole, AppRoleDTO>(resulAsync); } catch (Exception ex) { HandleSVCException(ref response, ex); } return(response); }
public async Task <BLResponse <List <EmployeeDTO> > > GetAllAsync() { var response = new BLResponse <List <EmployeeDTO> >(); try { var empsAsync = await Uow.Employees.AllAsync(e => e.Gender == Model.GenderEnum.MAN, o => o.OrderBy(e => e.BirthDate), e => e.AppUser); response.Data = Mapper.Map <List <Employee>, List <EmployeeDTO> >(empsAsync.ToList()); } catch (Exception ex) { HandleSVCException(ref response, ex); } return(response); }
// GET: api/Integrations/harunk public HttpResponseMessage GetIntegration(string name, string exportType) { BLIntegration blIntegration = new BLIntegration(); BLResponse <IntegrationModel> integrationResponse = blIntegration.GetIntegration(name, exportType); if (integrationResponse.ResponseCode == ResponseCode.Fail) { return(new HttpResponseMessage { Content = new StringContent(integrationResponse.ResponseMessage), StatusCode = HttpStatusCode.BadRequest }); } return(new HttpResponseMessage { Content = new StringContent(integrationResponse.ResponseData.Content, Encoding.UTF8, "application/xml"), StatusCode = HttpStatusCode.OK }); }
public async Task <BLResponse <bool> > DeleteRoleAsync(AppRoleDTO pDto) { var response = new BLResponse <bool>(); try { var resulAsync = await Uow.Roles.DeleteRoleAsync(pDto.Id); if (resulAsync.Succeeded) { response.Data = resulAsync.Succeeded; } else { HandleSVCException(ref response, resulAsync.Errors.ToArray()); } } catch (Exception ex) { HandleSVCException(ref response, ex); } return(response); }
public void Complete(EntityOperation operation, ref BLContext context, ref BLResponse response) { }
protected void HandleSVCException <T>(ref BLResponse <T> pResponse, params string[] pErrors) { pResponse.HasErrors = true; pResponse.Errors.Add("Error at Business Service"); pResponse.Errors.AddRange(pErrors); }
public async Task <BLResponse> LogoutAsync() { await _accountManager.SignOutAsync(); return(BLResponse.GetVoidResponse()); }
public BLResponse<Author> GetAuthor(GetAuthor request, BLRequest blRequest){ return Client.Execute(proxy=>{ var u= Authors.FirstOrDefault(proxy, f=>f.Id==request.Id); if( u==default(Author)) throw new BLException("Author not found. Id:'{0}'".Fmt(request.Id)); var r = new BLResponse<Author>(); if(!IsCayita(blRequest)) r.Result.Add(u); else { var grid = BuildAuthorGrid(new List<Author>()); var dr =grid.CreateRow(u); r.Html= dr.ToString(); } return r; }); }
protected void HandleSVCException(Exception pEx) { HandleSVCException(BLResponse.GetVoidResponse(HttpStatusCode.InternalServerError), pEx); }